How to get players and change them into a value

So I made 4 string values.

  • One
  • Two
  • Three
  • Four

Im trying to change the values of them to each player in the server. (Max 4)
When I try to do this it usually makes for example One, Two the same player
I want each value to hold a different player name.

How do I script this?

You are able to do this which you can get the Player’s with game.Players:GetPlayers()
You would use a for loop for this to run 4 times:

local Players = game.Players:GetPlayers()
for index = 1,4 do
Example[index].Value = Players[index] -- gets the Player and assigns value from index order

end

If you want it to be random, you would do this:

local Players = game.Players:GetPlayers()
for index = 1,4 do
local RandomPlr = Players[math.random(1, #Players)] -- gets Random Player
Example[index].Value = RandomPlr -- Assigns Random Player
table.remove(Players, Players[RandomPlr]) -- removes Plauyer so they arent chosen again
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.