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

My script isn't working correctly?

This script is supposed to switch between maps every 30 seconds. For some reason, it's not doing that. It's not saying anything in output, and the text gui doesn't say anything either. Help?

for i,v in pairs(game.Players:GetChildren()) do
	local maps = game.ServerStorage:FindFirstChild("Maps")
	local gui = v.PlayerGui:FindFirstChild("MapAnnouncer")
	local guitext = gui:FindFirstChild("AnnouncerText")

	while true do
		wait(3)
		chosenmap = maps[math.random(1, #maps)]
		chosenmap.Parent = game.Workspace
	
		guitext.Text = "Map Chosen: " ..chosenmap.Name
	
		for i = 30, 0, -1 do
			if i <= 9 then
				game.Workspace.TimerCount:Play()
				guitext.Text = "New game starts in: (0:0"..i..")"
			else
				game.Workspace.TimerCount:Play()
				guitext.Text = "New game starts in: (0:"..i..")"
			end
			wait(1)
		end
	end
end

1 answer

I changed the order of this script, let me know if there are any problems with it as I cannot test it.

while true do

	local maps = game.ServerStorage:FindFirstChild("Maps")
	chosenmap = maps[math.random(1, #maps)]
    chosenmap.Parent = game.Workspace
	
	--update all of the players gui text 
	for i,v in pairs(game.Players:GetChildren()) do	
		local gui = v.PlayerGui:FindFirstChild("MapAnnouncer")
		local guitext = gui:FindFirstChild("AnnouncerText")
		guitext.Text = "Map Chosen: " ..chosenmap.Name
	end
	
	for i = 30, 0, -1 do
	
		for i,v in pairs(game.Players:GetChildren()) do	
			local gui2 = v.PlayerGui:FindFirstChild("MapAnnouncer")
			local guitext2 = gui:FindFirstChild("AnnouncerText")
			
			
			if i <= 9 then
                guitext.Text = "New game starts in: (0:0"..i..")"
            else
                guitext.Text = "New game starts in: (0:"..i..")"
            end
			
		end
		
		game.Workspace.TimerCount:Play() -- play sound then wait
		wait(1)
		
	end

end

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