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

Help With Teleporting Players And Team Setting?

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)))
wait(1)

local debounce = true
while debounce == true do
	if getPlayerNumberInTeam(tostring(game.Teams.Death.TeamColor)) == 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) == 0 then
		debounce = false
		wait()
	end
	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
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.

local debounce = true
while debounce == true do
	if getPlayerNumberInTeam(tostring(game.Teams.Death.TeamColor)) == 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) == 0 then
		debounce = false
		wait()
	end
	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 makes it up to the part where it checks Death and Runners for players, but then it doesn't do anything. Some help?

2 comments

0

could you explain more? What do you mean by "It does things and works fine if I set one of the teams to Dead, but otherwise it doesn't work."?

0

Sorry, I fixed it. That part should've been there, it didn't make sense and I'm not sure why I typed that.

1 answer

✓ Accepted answer

The problem is at line 16, you're not checking if the number of player is not equal to 0. Instead you're checking if the number of players is 0.

Line 16 should be: if getPlayerNumberInTeam(tostring(game.Teams.Dead.TeamColor)) ~= 0 or getPlayerNumberInTeam(tostring(game.Teams.Runners.TeamColor)) ~= 0 then

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