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

Why won't this recognize the script?(unanswered)

I have two separate pieces of script here. Basically it displays a message if the team "survivors" has no players left. It works only in single player but when I tried to play with someone who always lags it failed to work.

function getTeam(team)
    local players = game.Players:GetPlayers();
    local teamPlayers = {};
    for _, player in pairs(players) do
        if player.TeamColor == team.TeamColor then
            table.insert(teamPlayers, player);
        end
    end
    return teamPlayers;
end
if #getTeam(game.Teams.Survivors) == 0 then
		m = Instance.new("Message",Workspace)
			m.Text = "The final survivor was infected. Once you respawn the round will begin!"
		wait(3)
	m:Destroy()	

Any reasons why this wouldn't work? Thanks

4 comments

0

What exactly happens that shouldn't?

0

No message appears

0

That will only run once.

0

I know there is a separate part that renames the functions in order. Will it continuously check?

1 answer

If you are trying to get the total number of teamPlayers, why don't you do #teamPlayers? You could run the function right before the if statement so that teamPlayers will have a value.

such as:

getTeam(game.Teams.Survivors)
if #teamPlayers == 0 then
	m = Instance.new("Message", Workspace)
	m.Text = "The final survivor was infected. Once you respawn the round will begin!"
	wait(3)
	m:Destroy()
end

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