So, I'm making a game where all players must change teams after sixty seconds. But my method doesn't work, how can I do it?
Actual code : (Script in serverScriptService)
local players = game.Players:GetPlayers() function launchGame() players.TeamColor = BrickColor.new("Burlap") players:LoadCharacter() end wait(60) launchGame()
Problem
You are setting the index of the players table "TeamColor" to a new Burlap BrickColor. You are also attempting to call the LoadCharacter method on the table returned by game.Players:GetPlayers()
.
Solution
Use a for loop to iterate through the table and set the team colors of each player, and load their characters.
Code
local players = game.Players:GetPlayers() function launchGame() for _,player in ipairs(players) do player.TeamColor = BrickColor.new("Burlap") player:LoadCharacter() end end wait(60) launchGame()
Conclusion
If you have any more questions, feel free to reach out to me on Discord (phxntxsmic#2021)
.
wait(60) for i,v in pairs(game.Players:GetPlayers()) do --Loop through all players v.Team = game.Teams.Team --Change ''Team'' for the name of the team v:LoadCharacter() end