I can't seem to get this script to work:
game.Players.PlayerAdded:connect(function(playerAdded)
print(player.Name)
end)
The goal of the script is to print the player's name once they enter the game. Can anyone help?
I can't seem to get this script to work:
game.Players.PlayerAdded:connect(function(playerAdded)
print(player.Name)
end)
The goal of the script is to print the player's name once they enter the game. Can anyone help?
You only made one mistake. That what is in between the parenthesis after the function keyword, are the parameters. The value returned from the PlayerAdded event is the/a player. This data is stored in the parameter. The parameter essentially acts like a variable and it value is received from the event in this case.
The parameter - or variable, if you would prefer that - playerAdded contains the player. To fix your script, there are two options:
game.Players.PlayerAdded:connect(function(playerAdded)
print(playerAdded.Name)
end)
game.Players.PlayerAdded:connect(function(player)
print(player.Name)
end)
game.Players.PlayerAdded:connect(function(player) -- This is the player. The PlayerAdded event knows who the player is.
print(player.Name) -- Printing the player name.
end)
When you have the event PlayerAdded, the function's parameters will always be the player.
Make sure it is in a LocalScript.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Once again I am being down-voted for trying to help...