I'm trying to make a billboard gui show up when you get near a specific npc, however, i cant even figure out how to detect when the player moves. I can't seem to figure out what i'm doing wrong, the error is
Players.Galaxybombboy.PlayerGui.LocalScript:7: attempt to index nil with 'Changed'
and the script is
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local rockman = workspace["Rock Man - Shop Keeper"] local rockhumroot = rockman:FindFirstChild("HumanoidRootPart") character:FindFirstChild("HumanoidRootPart").Changed:Connect(function() if (character:FindFirstChild("HumanoidRootPart").Position - rockhumroot.Position).Magnitude < 50 then print("working") end end)
What am i doing wrong?
You Cant Cause When Your In Game And You Walk And When You open Your Characters Humanoid Root Part Properties The Position Wont Change So It Would be Better If You use Head That Would Work :D
Code Replaced By Head:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local rockman = workspace["Rock Man - Shop Keeper"] local rockhumroot = rockman:FindFirstChild("Head") character:FindFirstChild("Head"):GetPropertyChangedSignal("Position"):Connect(function() if (character:FindFirstChild("Head").Position - rockhumroot.Position).Magnitude < 50 then print("working") end end)
You should try changing
character:FindFirstChild("HumanoidRootPart")
to
character:WaitForChild("HumanoidRootPart")
Let me know if this works!