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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
Robowon1 323 Moderation Voter
3 years ago

Use WaitForChild() instead of FindFirstChild()

0
i've already tried this, it makes an infinite wait Galaxybombboy 134 — 3y
0
NEVERMIND THANKS BRO THIS WORKS I TRIED IT AGAIN Galaxybombboy 134 — 3y
Ad

Answer this question