Why am I getting - Workspace.R15.Script:5: attempt to index nil with 'HumanoidRootPart'?

I’m attempting to make a Titan from AOT, and trying to make it move towards a player. The problem is whenever I test it I get ’ - Workspace.R15.Script:5: attempt to index nil with ‘HumanoidRootPart’'.

I’ve tried searching it up on youtube but got nothing.

It is a script inside the titan model.

local Distance = 100
local Titan = script.Parent

game.Players.PlayerAdded:Connect(function(player)
	playerPos = player.Character.HumanoidRootPart
	Titan.Humanoid.WalkToPoint(playerPos.CFrame)
end)
1 Like

Since the player loads before the character, character is nil when you try to use it.

You need to use CharacterAdded.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- now you can use character
    end)
end)

Note that that means whatever you put in there will run every time the player respawns. You’ll need to disconnect the CharacterAdded event inside the handler if you only want it to run the first time.

2 Likes

Thanks, the error is gone but it shows
Workspace.R15.Script:7: attempt to call a Vector3 value
and when I use Vector3 it says it’s not apart of the part.

1 Like

WalkToPoint is a property, not a method (and anyways, its a Vector3, not a CFrame). I don’t think you can set it directly, but possibly. Change that line to:

Titan.Humanoid:MoveTo(playerPos.Position)

The above changes the WalkToPoint, and should work fine. You can also try (not sure if this works though) setting it directly:

Titan.Humanoid.WalkToPoint = playerPos.Position
2 Likes