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

'Attempt to index nil with 'Position' '??

For some reason, My script gives me the error 'Attempt to index nil with 'Position' '?? And i dont know how to fix it, here is the part thats giving me the error

Error part:

Character:FindFirstChild('HumanoidRootPart').Position.Changed:Connect(function()

And variables if it matters

local Player = game.Players.LocalPlayer
local Character = Player.Character

8 comments

0

Try using waitforchild instead of find first child, the hrp may npt have loaded in yet

0

Lemme try

0

it didnt work. as if its infinitely searching and doesnt find it

0

where is the script stored?

0

answered, check it out

0

Make sure it's a local script

0

I changed my answer!

0

no read the article

2 answers

Your problem is that you are using .Changed on a separate property. To solve this either try using :GetPropertyChangedSignal() or remove .Position. New code:

Character:WaitForChild('HumanoidRootPart').Changed:Connect(function() -- // Use WaitForChild instead of FindFirstChild to prevent errors.

To learn to use GetPropertyChangedSignal, check out this: https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal

5 comments

0

How would i use ':GetPropetyChangedSignal()

0

Thanks, I'll go try

0

So like.. Character:FindFirstChild('HumanoidRootPart'):GetPropertyChangedSignal("Position"):Connect(function() ? Cause im getting the error ' attempt to index nil with 'GetPropertyChangedSignal'

0

What am i doing wrong though? im trying to read the article but im extremely confused

0

Oh, I just figured it out, sorry

i try to write down your code and check it, i think the problem is you cant use position.changed thing. You can try to use this function :GetPropertyChangedSignal

1 comment

0

While :GetPropertyChangedSignal is the better way to go, it is not the solution

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