Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
10 years ago

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.

0
The problem with this script is, it doesn't account for when people leave. AmericanStripes 610 — 10y
0
Oh yea...I should probably fix that... dyler3 1510 — 10y
Ad

Answer this question