I'm trying to fix my countdown function. How did I make 120 timers?

Specifically this script

for i = 120, 0, -1 do
			if timer > 0 then
				if completedminigame == false then
					print("timer")
					timer = timer - 1
					textmaker.Text = timer
					wait(1)
				else
					for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
						v:Destroy()
					end
					textmaker.Text = ""
					Player.Character:WaitForChild("Board"):Destroy()
					game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
					wait(1)
					textmaker.Text = ""

				end
			elseif timer <= 0 then
				print("Minigame failed")
				for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
					v:Destroy()
				end
			end
			textmaker.Text = ""
			Player.Character:WaitForChild("Board"):Destroy()
			game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
			Player.Character:WaitForChild("Humanoid").Health = 0
			wait(1)
			textmaker.Text = ""
		end

some other guy said i made 120 timers. How do i fix this?
I want it to go down to 0
but it goes to zero instantly by the next second

1 Like

not a lot to go off here, as there seem to be a couple of missing variables and you havent told what exactly you wanted it to do.

howeverr i believe the problem is that the variable named timer should actually be the i for the for loop.

Okay so the timer variable is 120

I think i already tried that. i doesn’t work because when it hits 0 it doesn’t use the other if function

still not a lot to go off of, but have you tried to put continue and break at the end of some of your if statements?

Wait im sorry lemme give you the entire script

local Player = game.Players.LocalPlayer
local localpart1 = game:GetService("ReplicatedStorage").Skateboard:Clone()
local Players = game.Players:GetPlayers()
local repi = game:GetService("ReplicatedStorage")
localpart1.Parent = workspace
local timer = 15
local completedminigame = false
local BadgeService = game:GetService("BadgeService")
print("variable")
local Players = game:GetService("Players")
print("variable")
local cat = Player.PlayerGui.BananaPedia.GUI.Structure.ScrollingFrame.SkaterCat
local textmaker = Player.PlayerGui.NewDialouge.TextLabel
print("variable")
local ts = game:GetService("TweenService")
print("variable")
local ti1 = TweenInfo.new(2,Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
print("variable")
local ti2 = TweenInfo.new(1,Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
print("variable")
local sound = game.Players.LocalPlayer.PlayerGui.MainMenu.poo.SoundPlayer.Main
print("variable")
local image = Player.PlayerGui.Collected.Winner
print("variable")
local currentrotation = image.ImageLabel.Rotation
print("variable")
local plr = game.Players.LocalPlayer
print("variable")

local db = false
print("variable")

local Part = script.Parent
print("variable")
print("variable")

local debounce = true
print("variable")
local Player = game.Players.LocalPlayer
local ab = false

localpart1.Touched:Connect(function()
	if not ab then
    ab = true
	repi.DD:WaitForChild("0"):FireServer()
	print("Starting Minigame")
			print("Addressed player"..Player.Name)

	Player.Character:MoveTo(workspace.teleport.PrimaryPart.Position)
	game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)
	local c = workspace.Minigames["Skater Banana Cat"].Board
	c.Parent = workspace
	c.PrimaryPart = c.SkateboardPlatform
	local char = Player.Character
	local position = workspace.teleport.PrimaryPart.CFrame
	local clone = game:GetService("ReplicatedStorage").AssistantSkate:Clone()
	clone.Parent = workspace.CurrentCamera
	wait(1)
	local items = workspace.Minigames["Skater Banana Cat"]:GetChildren()
	local item = items[math.random(1, #items)]
	item.Parent = workspace
	item:PivotTo(position)
	local text = {"You will race around the map in a time limit. Follow the checkpoints."}
	textmaker:TweenPosition(UDim2.new(0.225, 0,0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1)
	for i,v in ipairs(text) do
		for i = 0, string.len(v) do
			wait(0.025)
			script.poo:Play()
			textmaker.Text = string.sub(v, 1, i)
		end
		wait(string.len(v) / 25)
	end
	repi.DD:WaitForChild("50"):FireServer()
	local clone1 = game:GetService('ReplicatedStorage'):WaitForChild("Check"):WaitForChild("Checkpoint(1)"):Clone()
		clone1.Parent = workspace.CurrentCamera
		for i = 120, 0, -1 do
			if timer > 0 then
				if completedminigame == false then
					print("timer")
					timer = timer - 1
					textmaker.Text = timer
					wait(1)
				else
					for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
						v:Destroy()
					end
					textmaker.Text = ""
					Player.Character:WaitForChild("Board"):Destroy()
					game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
					wait(1)
					textmaker.Text = ""

				end
			elseif timer <= 0 then
				print("Minigame failed")
				for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
					v:Destroy()
				end
			end
			textmaker.Text = ""
			Player.Character:WaitForChild("Board"):Destroy()
			game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
			Player.Character:WaitForChild("Humanoid").Health = 0
			wait(1)
			textmaker.Text = ""
		end
		ab = false
	end
end)
	
local rep = game:GetService("ReplicatedStorage")

workspace.CurrentCamera:WaitForChild("Checkpoint(1)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
			-- do something here
	workspace.CurrentCamera:WaitForChild("Checkpoint(1)"):Destroy()
	script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(2)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
		end
end)

workspace.CurrentCamera:WaitForChild("Checkpoint(2)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
	workspace.CurrentCamera:WaitForChild("Checkpoint(2)"):Destroy()
	script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(3)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
		end
end)

workspace.CurrentCamera:WaitForChild("Checkpoint(3)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
	workspace.CurrentCamera:WaitForChild("Checkpoint(3)"):Destroy()
	script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(4)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
end
end)
workspace.CurrentCamera:WaitForChild("Checkpoint(4)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
	workspace.CurrentCamera:WaitForChild("Checkpoint(4)"):Destroy()
	script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(5)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
		end
end)
workspace.CurrentCamera:WaitForChild("Checkpoint(5)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
	workspace.CurrentCamera:WaitForChild("Checkpoint(5)"):Destroy()
	script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(Finish)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)
workspace.CurrentCamera:WaitForChild("Finish"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		completedminigame = true
		Player.Character:WaitForChild("Board"):Destroy()
		print("Found humanoid")
		workspace.CurrentCamera:WaitForChild("Finish"):Destroy()
		print("Destroyed")
		script.Sound:Play()
		print("Sound")
		for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
			print("Ipairs")
			if v.Name == "Skateboard" then
				print("Yeah no")
				print("no")
			else
				print("destroy")
				v:Destroy()
			end
		end
		print("variable")
			print("no ooooooo aaaaa")
		debounce = false
		print("event")
		print("event")
		debounce = true
		print("event")
		if db == false and plr:WaitForChild("Bananacats"):WaitForChild("SkaterBananaCat").Value == false then
			print("event")
			rep.Cat.Skatefr:FireServer()
			print("event")
			db = true
			print("event")
		local din = cat.Information
		local catname = din.NName.Value
		local catimage = din.Image.Texture
		local catdiff = din.Difficulty.Value
		local catdiffcol = din.DifficultyColor.Value
		image.ImageLabel.Image = catimage
		image.ImageLabel.diff.Text = catdiff
		image.ImageLabel.diff.TextColor3 = catdiffcol
		image.ImageLabel.TextLabel.Text = "You got: "..catname
		ts:Create(sound, ti1, {Volume = 0.3}):Play()
		wait()
		image:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
		wait()
		script.yoo:Play()
			wait()
			Player.Character:WaitForChild("Humanoid").Health = 0
            wait(3)
				ts:Create(sound, ti1, {Volume = 1}):Play()
				image:TweenPosition(UDim2.new(0,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
				db = false
			end
    end
end)

Yes i used a bunch of prints because im so bad at fixing bugs

I already put the timer variable at 120 roblox studio didnt save my updated script
it didnt work

this script is itself a act against god.
who names a instance script.poo?

Okay so the timer variable is 120

…its set to 15

also you never set it back to 15 after the function finishes so it’d only one run once before breaking, unless this script was only meant to run once that is a major flaw and is also the same problem with the completedminigame bool.

i tried to fix it so see if this new script solves your problem

local Player = game.Players.LocalPlayer
local localpart1 = game:GetService("ReplicatedStorage").Skateboard:Clone()
local Players = game.Players:GetPlayers()
local repi = game:GetService("ReplicatedStorage")
localpart1.Parent = workspace
local completedminigame = false
local BadgeService = game:GetService("BadgeService")
print("variable")
local Players = game:GetService("Players")
print("variable")
local cat = Player.PlayerGui.BananaPedia.GUI.Structure.ScrollingFrame.SkaterCat
local textmaker = Player.PlayerGui.NewDialouge.TextLabel
print("variable")
local ts = game:GetService("TweenService")
print("variable")
local ti1 = TweenInfo.new(2,Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
print("variable")
local ti2 = TweenInfo.new(1,Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
print("variable")
local sound = game.Players.LocalPlayer.PlayerGui.MainMenu.poo.SoundPlayer.Main
print("variable")
local image = Player.PlayerGui.Collected.Winner
print("variable")
local currentrotation = image.ImageLabel.Rotation
print("variable")
local plr = game.Players.LocalPlayer
print("variable")

local db = false
print("variable")

local Part = script.Parent
print("variable")
print("variable")

local debounce = true
print("variable")
local Player = game.Players.LocalPlayer
local ab = false

localpart1.Touched:Connect(function()
	if not ab then
		ab = true
		repi.DD:WaitForChild("0"):FireServer()
		print("Starting Minigame")
		print("Addressed player"..Player.Name)

		Player.Character:MoveTo(workspace.teleport.PrimaryPart.Position)
		game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)
		local c = workspace.Minigames["Skater Banana Cat"].Board
		c.Parent = workspace
		c.PrimaryPart = c.SkateboardPlatform
		local char = Player.Character
		local position = workspace.teleport.PrimaryPart.CFrame
		local clone = game:GetService("ReplicatedStorage").AssistantSkate:Clone()
		clone.Parent = workspace.CurrentCamera
		wait(1)
		local items = workspace.Minigames["Skater Banana Cat"]:GetChildren()
		local item = items[math.random(1, #items)]
		item.Parent = workspace
		item:PivotTo(position)
		local text = {"You will race around the map in a time limit. Follow the checkpoints."}
		textmaker:TweenPosition(UDim2.new(0.225, 0,0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1)
		for i,v in ipairs(text) do
			for i = 0, string.len(v) do
				wait(0.025)
				script.poo:Play()
				textmaker.Text = string.sub(v, 1, i)
			end
			wait(string.len(v) / 25)
		end
		repi.DD:WaitForChild("50"):FireServer()
		local clone1 = game:GetService('ReplicatedStorage'):WaitForChild("Check"):WaitForChild("Checkpoint(1)"):Clone()
		clone1.Parent = workspace.CurrentCamera
		
		local function End()
			textmaker.Text = ""
			Player.Character:WaitForChild("Board"):Destroy()
			game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
			textmaker.Text = ""
		end
		
		for i = 120, 0, -1 do
			wait(1)
			if i == 0 then
				End()
				break
			end

			if completedminigame then
				End()
				break
			end

			textmaker.Text = i
		end
		ab = false
	end
end)

local rep = game:GetService("ReplicatedStorage")

workspace.CurrentCamera:WaitForChild("Checkpoint(1)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		-- do something here
		workspace.CurrentCamera:WaitForChild("Checkpoint(1)"):Destroy()
		script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(2)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)

workspace.CurrentCamera:WaitForChild("Checkpoint(2)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		workspace.CurrentCamera:WaitForChild("Checkpoint(2)"):Destroy()
		script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(3)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)

workspace.CurrentCamera:WaitForChild("Checkpoint(3)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		workspace.CurrentCamera:WaitForChild("Checkpoint(3)"):Destroy()
		script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(4)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)
workspace.CurrentCamera:WaitForChild("Checkpoint(4)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		workspace.CurrentCamera:WaitForChild("Checkpoint(4)"):Destroy()
		script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(5)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)
workspace.CurrentCamera:WaitForChild("Checkpoint(5)"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		workspace.CurrentCamera:WaitForChild("Checkpoint(5)"):Destroy()
		script.Sound:Play()
		local aaa =	rep.Check["Checkpoint(Finish)"]:Clone()
		aaa.Parent = workspace.CurrentCamera
	end
end)
workspace.CurrentCamera:WaitForChild("Finish"):WaitForChild("Touch").Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		completedminigame = true
		Player.Character:WaitForChild("Board"):Destroy()
		print("Found humanoid")
		workspace.CurrentCamera:WaitForChild("Finish"):Destroy()
		print("Destroyed")
		script.Sound:Play()
		print("Sound")
		for i,v in ipairs(workspace.CurrentCamera:GetChildren()) do
			print("Ipairs")
			if v.Name == "Skateboard" then
				print("Yeah no")
				print("no")
			else
				print("destroy")
				v:Destroy()
			end
		end
		print("variable")
		print("no ooooooo aaaaa")
		debounce = false
		print("event")
		print("event")
		debounce = true
		print("event")
		if db == false and plr:WaitForChild("Bananacats"):WaitForChild("SkaterBananaCat").Value == false then
			print("event")
			rep.Cat.Skatefr:FireServer()
			print("event")
			db = true
			print("event")
			local din = cat.Information
			local catname = din.NName.Value
			local catimage = din.Image.Texture
			local catdiff = din.Difficulty.Value
			local catdiffcol = din.DifficultyColor.Value
			image.ImageLabel.Image = catimage
			image.ImageLabel.diff.Text = catdiff
			image.ImageLabel.diff.TextColor3 = catdiffcol
			image.ImageLabel.TextLabel.Text = "You got: "..catname
			ts:Create(sound, ti1, {Volume = 0.3}):Play()
			wait()
			image:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
			wait()
			script.yoo:Play()
			wait()
			Player.Character:WaitForChild("Humanoid").Health = 0
			wait(3)
			ts:Create(sound, ti1, {Volume = 1}):Play()
			image:TweenPosition(UDim2.new(0,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
			db = false
		end
	end
end)
1 Like

I have my ways of scripting :grin: :grin: :grin: :grin: :grin: :grin:

now that i think about it i think im going mentally insane over this script

thats understandable, it does infact look like a Cognito hazard

1 Like

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