Issue with script

Hello Developers!

I have an issue that when I join my game, the intermission doesn’t go down by 1. It is the same with the other timers.

Script:

local InGame = game.ReplicatedStorage.InGame
local FloorGlass = game.Workspace.GameSpawn.FloorGlass
local gameRoundTimer = 5
local roundLength = 5
local intermissionLength = 10
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local RoundEnd = game.ReplicatedStorage.RoundEnd

local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameSpawn.GameAreaSpawn


RoundEnd.Changed:Connect(function()
	if RoundEnd == true then
		Status.Value = "Game Over!"
		local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
		
		Controls:Disable()
	end
end)


InGame.Changed:Connect(function()
	if InGame.Value == true then
		FloorGlass.Transparency = 1
		FloorGlass.CanCollide = false
		wait(5)
		FloorGlass.Transparency = 0.5
		FloorGlass.CanCollide = true
	end
end)


InRound.Changed:Connect(function()
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetPlayers()) do
			local char = player.Character
			char:WaitForChild("HumanoidRootPart").CFrame = GameAreaSpawn.CFrame * CFrame.new(0,3.25,0)
		end
	else
		for _, player in pairs(game.Players:GetPlayers()) do
			local char = player.Character
			char:WaitForChild("HumanoidRootPart").CFrame = LobbySpawn.CFrame * CFrame.new(0,3.25,0)
		end
	end
end)

local function roundTimer()
	while wait() do
		InRound.Value = false
		for i = intermissionLength, 0, -1 do
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
			wait(10)
			InRound.Value = true
		end
		for i = gameRoundTimer, 0, -1 do
			wait(1)
			Status.Value = "Dropping Players: ".. i .." seconds left!"
			wait(5)
			InGame = true
		end
		for i = roundLength, 0, -1 do
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
			wait(5)
			RoundEnd = true
		end
	end
end

coroutine.wrap(roundTimer)()

Thanks for reading!:stuck_out_tongue_winking_eye:

You could try printing what i is for every loop? Also idk if this is intentional

Whats the wait(10) for? If you’re intending your intermission to be 10 seconds long you should try remove the wait(10)

What does the output say? Is there any error?

I think the time of the intermission

Remove the wait(10) because thats just making it wait 11 seconds between each iteration of your loop

1 Like

It shouldn’t be wait(10) since there already is a wait(1) which makes every time it iterates it waits 1 second

Try implementing this script for your roundTimer function:

local function roundTimer()
	while wait() do
		InRound.Value = false

		for i = intermissionLength, 0, -1 do
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		InRound.Value = true

		for i = gameRoundTimer, 0, -1 do
			wait(1)
			Status.Value = "Dropping Players: ".. i .." seconds left!"
		end
		InGame = true

		for i = roundLength, 0, -1 do
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
		end
		RoundEnd = true

	end
end

Why it is skipping wait(10) then?

InRound.Value = false
for i = intermissionLength, 0, -1 do
   wait(1)
   Status.Value = "Intermission: ".. i .." seconds left!"
   if i = 0 then InRound.Value = true end
end

So the loop that is created is counting down from 10, and every 1 second it should update the value. If you have a wait(10) it is going to wait 10 seconds before moving on.

O, now i know it. Otherwise if u still want to use wait(10) you can use a Spawn(function())

Yeah you could but it’s unnecessary since after the loop has finished that is essentially waiting 10 seconds anyway. So what ever you need to do after 10 seconds you would just add it after the loop.

When I take away the waits, it just teleports me to the game spawn!

Make sure you keep wait(1).

1 Like