Still have questions? Join our Discord server and get real time help.
1

# how do i move the characters "root part"?

i have a script here:

game.Players.PlayerAdded:Connect(function(player)
local user = player.Character
player.Chatted:Connect(function(msg)
if msg == "code:123!x556" then
user.HumanoidRootPart.Position = Vector3.new(0,0,0)
end
end)
end)


and i have this error Workspace.Script:5: attempt to index nil with 'HumanoidRootPart' i dont even know what this means lol help please

1
skvyy 153
3 days ago

The issue here is that you are calling the HumanoidRootPart before it is loaded into the game.

A quick fix to this would be adding a

player.CharacterAdded:Wait()


The finished version is below!

local secretMessage = 'test'

local char = plr.Character or plr.CharacterAdded:Wait()
plr.Chatted:Connect(function(messageSent)
if messageSent == secretMessage then
char.HumanoidRootPart.Position = Vector3.new(0,0,0)
end
end)
end)

The error could be because you're calling the character immediately. In most cases, the character doesn't load as soon as the player joins, so you can try replacing local user = player.Character with local user = player.CharacterAdded:Wait() so the character is retrieved when it is loaded.