Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change team of players?

This script picks a random player and puts them on the assassins team but i want it to make the rest of the players to change to the Survivors team how do i do that

local SetNumber = 0
while true do
	wait(10)
	local players0 = game.Players:GetChildren()
	if #players0 >=1 and SetNumber <1 then
		local ItemToGive = game.Lighting.Tag
		local player = math.random(1, game.Players.NumPlayers);
		local Players = game.Players:GetPlayers()
		ItemToGive:Clone().Parent = Players[player].Backpack
		print (player)
		Players[player].Team = game.Teams.Assassins
		SetNumber = SetNumber + 1
		print(SetNumber) 
	end
end 


1 answer

✓ Accepted answer

Use the table.remove function on the table of players. It will still return the desired index, and will ensure that they cannot be found in the table. This way, you can iterate through the table and set everyone's team to Survivors.

Note: Lighting is not meant for storage. Place your item in ServerStorage.

local ItemToGive = game.ServerStorage.Tag --Lighting is not meant for storage!
local SetNumber = 0

function survivors(plrs) --function to convert team of plrs to survivors
	for _,v in next,plrs do
		v.Team = game.Teams.Survivors
	end
end

while wait(10) do
	local players = game.Players:GetPlayers()
	if #players >= 1 and SetNumber < 1 then
		local plr = math.random(#players);
		local player = table.remove(players,plr) --table.remove
		print(player)
		ItemToGive:Clone().Parent = player.Backpack
		player.Team = game.Teams.Assassins
		survivors(players) --call function
		SetNumber = SetNumber + 1
		print(SetNumber) 
	end
end 

3 comments

0

Thanks so much worked perfectly!

0

Np :D accept answer if I helped <3

0

How to I accept answer? Sorry i am really new to this website.

This discussion is preserved as it was. New answers, comments, and votes are closed.