Hello Scripting Helpers! I am working on a game and in one part the game chooses one player randomly and changes his team, this is the script:
function playeer() math.random(tick()) plr = game.Players:GetPlayers() print (math.random(#plr)) plr.TeamColor = "Really Red" wait(1) end wait(23) playeer()
The output only prints one number, this could be depending on the number of players, for example if theres 5 players it only prints one number which is positive and below 5, and so on like if theres 3 players, it prints a positive number below 3 or it could be 3, but thats the highest it could print due to the number of players. Also it doesn't changes the teamcolor.
Your main functionality problem is line 5.
You can't change the TeamColor of a list (which is what plr
equals; it's a list of all the players) and even if it wasn't a list, TeamColor is not a string value. There are some other problems, however, even if they won't affect the over-all functionality.
Line 2 is completely pointless.
Nothing is tabbed correctly.
Waiting one second at the end of the function will not accomplish anything unless you were doing something immediately after, which you are not.
plr
should be a local variable since you don't use it outside that function. This is more efficient.
plr
is not a good name for that variable, for it is not a specific player, but a list of all the players in the game.
playeer
as a function name does not make sense considering that you are changing all of the players' TeamColors to really red. The name should be chosen based on what you want to happen.
Here is my improved version of that script;
function changeTeamColors() local plrs = game.Players:GetPlayers print(math.random(#plrs)) for index,player in pairs(plrs) do --Loops through the list one at a time player.TeamColor = BrickColor.new("Really red") end end wait(23) changeTeamColors()