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

Round Timer Wont Assign Teams?

When the script runs, it goes through but when the intermission ends and the round begins, nothing happens, and players stay on neutral team.

--Round Variables
local timeint = 60 --Numbers read as seconds
local inttime = 60 --Numbers read as seconds
local requiredplayers = 2
--Round Objects
local status = game.ReplicatedStorage.Status
local teams = {"Red","Blue"}
local players = game.Players:GetChildren()
--Assign Teams
function Assign()
	for i = 1,#players do
		local ChosenTeam = teams[math.random(1,#teams)]
		players[i].TeamColor = game.Teams:FindFirstChild(ChosenTeam).TeamColor
	end
end
--Main
while wait() do
	for i=inttime,1,-1 do
		wait(1)
		status.Value = "Intermission: "..i
	end
	for i=timeint,1,-1 do
		Assign()
		wait(1)
		status.Value = "Time Left: "..i
	end
end

1 answer

The problem is that your script gets the children of players at the start and you reuse this same table so no new player will be added to the list, I would also recommend that you use GetPlayers.

...

-- this list is fixed we should be getting the players for each round
local players = game.Players:GetChildren()


--Assign Teams
function Assign()
    for i = 1,#players do
        local ChosenTeam = teams[math.random(1,#teams)]
        players[i].TeamColor = game.Teams:FindFirstChild(ChosenTeam).TeamColor
    end
end

...

All you need to do is move it into the function when it is ran we get a new list of player

...

--Assign Teams
function Assign()
    
    -- the new list of players
    local players = game.Players:GetPlayers()

    for i = 1,#players do
        local ChosenTeam = teams[math.random(1,#teams)]
        players[i].TeamColor = game.Teams:FindFirstChild(ChosenTeam).TeamColor
    end
end

...

I hope this helps.

1 comment

0

Still receiving the same issue

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