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

How do I make a script only run when a team has no players?

So I already have a script in my game that changes a players team the minute they die. So, say if all the players on a team have died, then the team is empty. I want to make it so that I can have a script that will only run after an entire team has died. However, I have a Neutral team as well, which will be empty when the round starts, so that one cant be included in the conditions to have it run.

1 answer

✓ Accepted answer

Insert a number value into the workspace. Set it at 0 to start off with and name it "TeamPlrz" (Or whatever else you want). Insert a script to do whatever you want and put this:

if game.Workspace.TeamPlrz.Value==0 then
--Put the rest of script here--
end

Now put this LOCALscript into the PlayerGui.

local Plr=game.Players.LocalPlayer

function Change(Color)
	if Color=="" then --Insert the team color that you want to be empty to start the script.
	game.Workspace.TeamPlrz.Value=game.Workspace.TeamPlrz.Value+1
	elseif Color=="" then --Insert the team color that you want players to be in when the script starts.
	game.Workspace.TeamPlrz.Value=game.Workspace.TeamPlrz.Value-1
end

function Left(Player)
	if Player.TeamColor=="" then --Insert the team color that you want to be empty to start the script.
	game.Workspace.TeamPlrz.Value=game.Workspace.TeamPlrz.Value-1
end

game.Players.PlayerRemoving:connect(Left)
Plr.Changed:connect(Change)

Now if you've done this correctly, then it should work. Comment if there's any problems.

2 comments

0

The problem with this script is, it doesn't account for when people leave.

0

Oh yea...I should probably fix that...

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