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
|
  |
| Joined: 13 Nov 2013 |
| Total Posts: 451 |
|
|
| 27 Aug 2017 10:49 PM |
bump
oh yeah, back to the top |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 13 Nov 2013 |
| Total Posts: 451 |
|
|
| 27 Aug 2017 10:53 PM |
| Where in the script do I put that? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 13 Nov 2013 |
| Total Posts: 451 |
|
|
| 28 Aug 2017 12:16 PM |
| ^^ That gives no error, but doesnt work. |
|
|
| Report Abuse |
|
|
Alend43
|
  |
| Joined: 13 Nov 2013 |
| Total Posts: 451 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 13 Nov 2013 |
| Total Posts: 451 |
|
|
| 28 Aug 2017 12:55 PM |
| bumppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|