I'm trying to make a confirm button that has a 5-second wait, but when you press the desired button, it waits a while before the countdown starts which lets the player instantly skip the 5 seconds. Here's the snippet:

script.Parent.Parent.Parent.Parent.PhoneMaker.Exit.MouseButton1Down:Connect(function()
for i = 5,0,-1 do
	wait(1)
	script.Parent.Text = "Wait"..i
end
script.Parent.Text = "Yes"
end)

The full script is here; I'm not sure if that part has to do anything with the snippet:

local pgui = game.Players.LocalPlayer.PlayerGui

script.Parent.Parent.Parent.Parent.PhoneMaker.Exit.MouseButton1Down:Connect(function()
for i = 5,0,-1 do
	wait(1)
	script.Parent.Text = "Wait"..i
end
script.Parent.Text = "Yes"
end) 

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "Yes" then
	script.Parent.Parent.Parent.Parent.PhoneMaker.Enabled = false
	script.Parent.Parent.Parent.Enabled = false
	workspace.MainMusic:Play()
	pgui.Buttons.Employee.Visible = true
	pgui.Buttons.PhoneMake.Visible = true
	pgui.Buttons.Employee.Selectable = false
	pgui.Buttons.PhoneMake.Selectable = false
	pgui.Buttons.Employee.Selected = false
	pgui.Buttons.PhoneMake.Selected = false
	for i = 1,50 do
		wait()
		workspace.CreateMusic.Volume = workspace.CreateMusic.Volume - .01
		workspace.MainMusic.Volume = workspace.MainMusic.Volume + .01
	end
	workspace.CreateMusic:Stop()
	pgui.PhoneMaker.Phone.Position = UDim2.new(0.398, 0,0.225, 0)
	pgui.PhoneMaker.Phone.Size = UDim2.new(0, 203,0, 328)
	wait()
	pgui.PhoneMaker.Phone.Image = "rbxassetid://1995879731"
	pgui.Buttons.Employee.Selectable = true
	pgui.Buttons.PhoneMake.Selectable = true
	pgui.Buttons.Employee.Selected = true
	pgui.Buttons.PhoneMake.Selected = true
	end
end)

Thanks in advance if you can help!

4 comments

0

Why not just use a debounce?

0

I had debounce in before, but it didn't do much. I might've had it in the wrong spot though.

0

Try implementing one, if it doesn't work adjust the code and we'll go from there. You currently have no "if", so its not checking anything before connecting the function.

0

I couldn't figure anything out scripting wise so I made the default text "Wait" and made it so whenever they go back the text is already at Wait. Not the best way, but it certainly works...