Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I keep on getting an error when trying to detect the humanoidrootpart moving. why is it doing this?

Asked by 3 years ago

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?

0
Use GetPropertyChangedSignal And Replace HumanoidRootPart With Head kidsteve923 139 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
Players.Galaxybombboy.PlayerGui.LocalScript:7: attempt to index nil with 'GetPropertyChangedSignal' Galaxybombboy 134 — 3y
0
thats the error im getting Galaxybombboy 134 — 3y
Ad
Log in to vote
0
Answered by
Neatwyy 123
3 years ago

You should try changing

character:FindFirstChild("HumanoidRootPart")

to

character:WaitForChild("HumanoidRootPart")

Let me know if this works!

0
It doesn't, I've already tried this sadly, it's an infinite waiting loop, as if there is no humanoid root part to be found inside of the character. Galaxybombboy 134 — 3y
0
Alright let me try this script my self, I'll let you know if I find a solution. Neatwyy 123 — 3y
0
This works perfectly fine for me. Could it be your other scripts interfering? Neatwyy 123 — 3y
0
did you use my whole script? Galaxybombboy 134 — 3y
View all comments (2 more)
0
whats the whole script you used? Galaxybombboy 134 — 3y
0
The error is only in line 7, so it isn't necessary to use your other variables that I don't have on my workspace. Neatwyy 123 — 3y

Answer this question