Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Can't find a way to get the character from the player?

Asked by 5 months ago

this is my code but I keep getting this error: ServerScriptService.Script:5: attempt to index nil with 'Character'

game.Players.PlayerAdded:Connect(function(player)
    print(player.name "joined")
end)

if not player.Character then
    print("waiting for character")
    player.CharacterAdded:wait();
    char = player.Character
else
    char = player.Character
end

1 answer

Log in to vote
2
Answered by 5 months ago
Edited 5 months ago

put your if statement inside the function. Your if statement does not know what player is because the player is a parameter of the function and it is only available for code inside the function (someone please explain this better).

0
Thank you this was really helpful! BRO_ITmeYO 120 — 5mo
Ad

Answer this question