When I put in a Touched event inside a countdown script it glitches

So I put in a Touched event into a countdown event for my game, and when I run it, it glitches like crazy I need to know how to fix that, thanks

local Sound1 = game.Workspace.Sound1
local Sound2 = game.Workspace.Sound2
local Cave = game.Workspace.Cave
local frame = script.Parent.Frame
local Count = game.Workspace.Elevator.Timer.SurfaceGui.TextLabel

game.ReplicatedStorage.Teleport.OnClientEvent:Connect(function()
	script.Parent.Frame.Visible = false
	Sound1.Playing = false
	Sound2.Playing = true
	script.Parent.Frame.Visible = true
	wait(3)
	Cave.Playing = true
	for i = 1,10 do
		frame.BackgroundTransparency += 0.1
		wait(0.01)
		Sound2.Playing = false
		script.Parent.TextLabel.Visible = true
		wait(4)
		Cave.Playing = false
	end
end)

game.ReplicatedStorage.Elevatormusic.OnClientEvent:Connect(function()
	game.Workspace.Elevator.Ebarrier.CanCollide = true
	script.Parent.Frame.Visible = false
	game.Workspace.Elevator.ElevatorMusic.ElevatorMusic.Playing = true
	
	local TweenService = game:GetService("TweenService")
	local Door = game.Workspace.Elevator.Door

	local goal = {}
	goal.Position = Vector3.new(227.527, -198.588, -18696.512)
	goal.Size = Vector3.new(7.089, 9.105, 0.825)

	local tweenInfo = TweenInfo.new(5)

	local tween = TweenService:Create(Door, tweenInfo, goal)
	
	wait(3)
	
	tween:Play()
	
	local seconds = 15
	
	repeat
		seconds = seconds -1
		Count.Text = seconds
		wait(1)
		
	until seconds == 0
	

	
end)

You likely did not implement a debounce system.

Could you clarify this?

It likely doesn’t follow the countdown in order

What do you mean by this statement?

When my player touches the Part it would start a timer like 10, 9, 8, 7 and so forth, but in this script the timer is like jumbled. Sorry I can’t explain this fully than show you what I meant

It’s likely you have the Touched event firing multiple times. Try to implement a debounce system.

Oh I see, I didn’t know it was fired multiple times lol

1 Like