I need help with a random map chooser

Hello Developers! So I made a random map chooser which chooses a map when the count down imer is end and teleports the player to the choosen map.The problem is that the countdown timer replays again and again.

Can you help me?

This is my script:


local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.SpawnLocation
local Maps = game.ServerStorage.Maps:GetChildren()
local ChoosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChoosenMap.SpawnLocation


--- Teleport ---

InGame.Changed:Connect(function()
	if InGame.Value == true then
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = ChoosenMap.SpawnLocation.CFrame
		end
	else 
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
		end
	end
end)


--- Intermission and game Timer ---

local function roundTimer()
	while wait() do
		for i = 30, 1, -1 do
			InGame.Value = false
			wait(1)
			Status.Value = "Game starts in:"..i
		end
		for i = 100, 1, 1 do
			InGame.Value = true
			wait(1)
			Status.Value = "Time left:"..i
		end
	end
end

spawn(roundTimer)
1 Like

What do you mean? Do you mean the countdown until teleportation keeps repeating?

I think it should be for i = 100, 1, -1 do, it will stop immediately

1 Like

Well, that’s sorta what it’s programmed to do. You check for changes in the value, but that should run asynchronously to the loop. All the loop does is constantly loop the timer, so that’s pretty expected behavior.

I don’t think so because the 100 is how much seconds

Oh lol didn’t even notice this. Never tried this with loops but that behavior makes sense lol

Yes but you’re incrementing it at a positive number. You’re telling it to start at 100 and stop at 1.

I mean the third parameter, it should count down not count up

Take this for example, you are counting down

the teleportion works only if the count down ends

It worked you solved it

Thank you!

Please mark this post as solution instead:

(edit): Can you read

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.