generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Whats wrong with this?!

Previous Thread :: Next Thread 
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
27 Aug 2017 10:20 PM
I have this BASIC and SIMPLE script.


local rootpart = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
local frame = script.Parent.ScreenGui.Frame
npc = game.Workspace.n0b:FindFirstChild("Torso")
distance = 12.5


while true do
if (rootpart.Position - npc.Position).Magnitude <= distance then
game:GetService("UserInputService").InputBegan:connect(function(PressedKey)
if PressedKey.KeyCode == Enum.KeyCode.E then
if frame.Visible == false then
frame.Visible = true
end
end
end)
elseif (rootpart.Position - npc.Position).Magnitude >= distance then
frame.Visible = false
end
wait(0.01)
end

Basically, when you press E while in a certain distance of the npc, a GUI Frame becomes visible. It works all find in Studio, but When I do it on a real server, it gives me this error: Players.Player1.PlayerGui.LocalScript:1: attempt to index field 'Character' (a nil value)
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
27 Aug 2017 10:49 PM
bump

oh yeah, back to the top
Report Abuse
gohan31865 is not online. gohan31865
Joined: 30 Jan 2011
Total Posts: 895
27 Aug 2017 10:52 PM
oh if thats the error then before u idenify rootpart, just do

repeat wait() until game.Players.LocalPlayer.CharacterAdded
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
27 Aug 2017 10:53 PM
Where in the script do I put that?
Report Abuse
JavaCoded is not online. JavaCoded
Joined: 31 Aug 2014
Total Posts: 31
27 Aug 2017 10:57 PM
@OP You need to set it as your first line in your script.

You could also do:

game.Players.LocalPlayer.CharacterAdded:Wait()

Both mine and gohan's method should work no matter what and both are equally efficient (I think.)


Let me hit that Yeet
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
27 Aug 2017 10:59 PM
That gives an error.

Players.Alend43.PlayerGui.LocalScript:1: function arguments expected near ':'
Report Abuse
ryan32t is not online. ryan32t
Joined: 30 Jun 2014
Total Posts: 188
27 Aug 2017 11:38 PM
This is your script but slightly editted... I changed the variables

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
char:WaitForChild('HumanoidRootPart')
rootpart = char.HumanoidRootPart
frame = player.PlayerGui.ScreenGui.Frame
npc = game.Workspace.n0b:FindFirstChild("Torso")
distance = 12.5


while true do
if (rootpart.Position - npc.Position).Magnitude <= distance then
game:GetService("UserInputService").InputBegan:connect(function(PressedKey)
if PressedKey.KeyCode == Enum.KeyCode.E then
if frame.Visible == false then
frame.Visible = true
end
end
end)
elseif (rootpart.Position - npc.Position).Magnitude >= distance then
frame.Visible = false
end
wait(0.01)
end
end)
end)
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:16 PM
^^ That gives no error, but doesnt work.
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:22 PM
bumpp
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:26 PM
I think this is my third bump? idk I lost count

oh yeah, back to the top
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:31 PM
probably bump 4.

starting to think my script isnt as BASIC and SIMPLE as I thought...
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:47 PM
bump5 I think?


Come on, Really no answers? Just one that fixes my script? ??
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:55 PM
bumppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
Report Abuse
Alend43 is not online. Alend43
Joined: 13 Nov 2013
Total Posts: 451
28 Aug 2017 12:58 PM
bump

Please? 1 Answer?

maybe Ill just start a new forum.
Report Abuse
xformula is not online. xformula
Joined: 03 Apr 2016
Total Posts: 69
28 Aug 2017 01:10 PM
try to do this in the beginning of your script


game.Players.LocalPlayer.CharacterAdded:wait()
wait(0.1)


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image