Attempt to Index nil with Position

Hello I have a script that allows you to run by pressing twice on W only I get this error and the character can not run anyone have the solution? I send the Script and a picture of the error if below.

Run.txt (4.6 KB)

The “Character” model does not yet have a primary part when you are trying to read it’s position.

Instead of

local lastPosition = Character.PrimaryPart.Position

Do this:

local primaryPart = Character:WaitForChild("HumanoidRootPart")
local lastPosition = primaryPart.Position

We know what the PrimaryPart of the character will be, so we can wait until we know it exists before trying to read it’s properties.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.