Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

0

Use GetPropertyChangedSignal And Replace HumanoidRootPart With Head

2 answers

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)

2 comments

0

Players.Galaxybombboy.PlayerGui.LocalScript:7: attempt to index nil with 'GetPropertyChangedSignal'

0

thats the error im getting

You should try changing

character:FindFirstChild("HumanoidRootPart")

to

character:WaitForChild("HumanoidRootPart")

Let me know if this works!

6 comments

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.

0

Alright let me try this script my self, I'll let you know if I find a solution.

0

This works perfectly fine for me. Could it be your other scripts interfering?

0

did you use my whole script?

0

whats the whole script you used?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.