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

Help With Player Teams And Death Detection?

Asked by
Scootakip 299 Moderation Voter
9 years ago
function getPlayerNumberInTeam(TeamColor)
local num = 0
for index,player in pairs(game.Players:GetChildren()) do
if tostring(player.TeamColor) == TeamColor and not player.Neutral then
num = num+1
end
end
return num
end

print(getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)))

while getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)) ~= 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) ~= 0 do
    getPlayerNumberInTeam()
    wait()
end

for i, player in ipairs(game.Players:GetChildren()) do
    player.TeamColor = game.Teams["Dead"].TeamColor
    player.Character:MoveTo(game.Workspace.SpawnLocation.Position + Vector3.new(0, i * 5, 0))
end

Ok, so it's easier for people to help me with this, I will explain what every part of the script does (or at least what it's supposed to do).

function getPlayerNumberInTeam(TeamColor)
local num = 0
for index,player in pairs(game.Players:GetChildren()) do
if tostring(player.TeamColor) == TeamColor and not player.Neutral then
num = num+1
end
end
return num
end

This is a function that gets the number of players in a certain team that you input the color of post-function script.


print(getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)))

This will use the function to print the number of players in the team color or teamname.teamcolor that you insert at the end of the command there.

while getPlayerNumberInTeam(tostring(game.Teams.Death.TeamColor)) ~= 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) ~= 0 do
    getPlayerNumberInTeam()
    wait()
end

This is supposed to wait until there aren't any players in one of the two teams: Death or Runners

for i, player in ipairs(game.Players:GetChildren()) do
    player.TeamColor = game.Teams["Dead"].TeamColor
    player.Character:MoveTo(game.Workspace.SpawnLocation.Position + Vector3.new(0, i * 5, 0))
end

It should then put everyone in the team "Dead" and teleport them to the spawn point.

The script gets up to the point where it prints how many people are in the specified team, it won't go further than that. Someone help me with this?

0
It never can get past the while loop because the while loop doesn't end. So the for loop doesn't happen. NoahWillCode 370 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

Perhaps you can try this to have the while loop run at the same time as the code below:

function getPlayerNumberInTeam(TeamColor)
local num = 0
for index,player in pairs(game.Players:GetChildren()) do
if tostring(player.TeamColor) == TeamColor and not player.Neutral then
num = num+1
end
end
return num
end

print(getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)))

spawn(function()
while getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)) ~= 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) ~= 0 do
    getPlayerNumberInTeam()
    wait()
end
end)

for i, player in ipairs(game.Players:GetChildren()) do
    player.TeamColor = game.Teams["Dead"].TeamColor
    player.Character:MoveTo(game.Workspace.SpawnLocation.Position + Vector3.new(0, i * 5, 0))
end

0
That seems to be a step in the right direction, but it seems to skip the whole idea of waiting for a player to not be in Death or Runners. Even if there is a player in both teams, it skips to the part where it sends all players to Dead. Scootakip 299 — 9y
Ad

Answer this question