So im trying to figure out how to get the player with a server script my game is a solo game so i feel like looping through all the players constantly would be useless is there a better way?
my attempt
1 | local plr = game.Players:WaitForChild( "Player" ) |
2 | print (plr.Name) |
this waits forever until it yields ;'/
Try this. I haven’t tested it yet.
Good luck.
1 | Players = game:GetService( "Players" ) |
2 | for i, player in pairs (Players:GetPlayers()) do |
3 | print (player.Name) |
4 | end |
To get a player you do:
1 | game.Players.PlayerAdded:Connect( function (player) —gets player |
2 | —code |
3 | end ) |
If you know the name of the player you're going to be looking for just do
1 | for i, v in pairs (game.Players:GetChildren()) do |
2 | if v.Name = = "NameOfWhoYouWant" then |
3 | --Code you want to use |
4 |
5 | break --So it stops since you already found who you want |
6 | end |
7 | end |