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

Why can't i recognise the players characters humanoid root part in my script?

I cant get my script to recognise HumanoidRootPart, I don't know if I'm messing up the Player variable, Character variable, or whatever. But it's like my character model doesnt have a humanoid root part (it does though?) anyone know whats going on?

Local Script (Location is StarterGui)

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumRoot = Character:FindFirstChild("HumanoidRootPart")
local ShopMan = workspace["Rock Man - Shop Keeper"]
local ShopRoot = ShopMan:FindFirstChild("HumanoidRootPart")

while true do
	if (HumRoot.Position - ShopRoot.Position).Magnitude < 30 then
		print("works")
	else
		print("nah not working")
	end
	wait()
end

Error Players.Galaxybombboy.PlayerGui.LocalScript:8: attempt to index nil with 'Position'

I think my studio is just broken, but that wouldnt make sense

1 answer

✓ Accepted answer

Use WaitForChild() instead of FindFirstChild()

2 comments

0

i've already tried this, it makes an infinite wait

0

NEVERMIND THANKS BRO THIS WORKS I TRIED IT AGAIN

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