Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
emervise 123
3 years 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 3 years ago
Edited 3 years 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! emervise 123 — 3y
Ad

Answer this question