Hey everyone, I am learning Roblox Lua and I wanted to know how could I get the Character for a Player. I tried the following code, but it does not work:
game.Players.PlayerAdded:Connect(function(player)
player.Team = game.Teams.Team1
player.Character.Humaoid.WalkSpeed = 100
end)
The error says “ServerScriptService.Script:3: attempt to index nil with ‘Humanoid’ - Server - Script:33”
Is there a way I could get the Character model into a variable or use right away?
9_Spy
(Spy)
February 28, 2021, 6:58pm
#2
Try doing
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
player.Team = game.Teams.Team1
character.Humanoid.WalkSpeed = 100
end)
end)
MLucarioEX_Shiny:
Humaoid
you forgot the “n” here aswell
iamajust
(iamajust)
February 28, 2021, 7:00pm
#3
When the player gets added, the character isn’t fully loaded yet. Use the player.CharacterAppearanceLoaded event. Updated code:
game.Players.PlayerAdded:Connect(function(player)
player.Team = game.Teams.Team1
player.CharacterAppearanceLoaded:Connect(function(character)
character.Humanoid.WalkSpeed = 100
end)
end)
Edit after 2 minutes:
@9_Spy Using player.CharacterAppearanceLoaded is better practice, because you’re sure everything has loaded correctly and no errors will occur.
Yea, right after I posted the topic I saw the typo. The code worked, thanks!
I see, if the player.CharacterAppearanceLoaded
is better, then I will try using it on my codes. Thanks!