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
4 years ago

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

01game.Players.PlayerAdded:Connect(function(player)
02    print(player.name "joined")
03end)
04 
05if not player.Character then
06    print("waiting for character")
07    player.CharacterAdded:wait();
08    char = player.Character
09else
10    char = player.Character
11end

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 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 — 4y
Ad

Answer this question