The graphic interface with a 5-second timer until it closes

this is the script, but the problem is that it is not timed normally, every second 4 appears but one second later 4 3 appears and the next second 4 3 2, but I want it, I hope I have explained it clearly
what changes should i make?

local touchPart = workspace.PlayingZone.Lava

touchPart.Touched:Connect(function(part)
	if part.Parent:FindFirstChildWhichIsA("Humanoid") then
		local Gui = script.parent
		Gui.Visible = true
		Gui.Text = "You will die in: 4"
		wait(1)
		Gui.Text = "You will die in: 3"
		wait(1)
		Gui.Text = "You will die in: 2"
		wait(1)
		Gui.Text = "You will die in: 1"
		wait(1)
		Gui.Visible = false
	end
end)

It might be because every time you touch the part it runs the function again. Try adding a debounce so it doesn’t run again right away.

what line of code do I need to debounce because I don’t realize that local debounce = false I already put at the beginning

or you say to replace wait with task.wait(1) is it better that way?

i really dont know whats the issue but try this instead

local touchPart = workspace.PlayingZone.Lava

touchPart.Touched:Connect(function(part)
    if part.Parent:FindFirstChildWhichIsA("Humanoid") then
        local Gui = script.Parent
        Gui.Visible = true

        for i = 4, 1, -1 do
            Gui.Text = "You will die in: " .. i
            task.wait(1)
        end
        
        Gui.Visible = false
    end
end)

it doesn’t work, it’s the same problem

oh, can you show a video of what’s the issue (i think its because youre touching the part every time and this triggers again i dont know really)

No, it’s just a debounce issue.

local shouldProcess = true

somePart.Touched:Connect(function(hit)
    if shouldProcess == false then return end
    shouldProcess = false

    -- your code that yields
    
    shouldProcess = true
end)
1 Like

@OniiSamaUwU @HpacAm everything is already working well, to whom can I tell that it helped me that you both made everything work well

You’re welcome, just be sure to mark something as a solution so this thread can close.

by the way, I would need a small modification, how do I make that gui stop showing after death? the problem is that I die on that part and after death that script starts working again and closes only after respawn

Easiest way is to set the ResetOnSpawn property of your ScreenGui to true, assuming your label is not visible from the start.

the problem is that I die on that part and after death that script starts working again and closes only after respawn

Assuming this is on the client:

  1. Make sure the person who hit is your LocalPlayer
  2. Check if the Humanoid is alive before showing the gui

Or you can just destroy the Gui all together if it’s a one-time thing anyways. It’ll just make a new one upon spawning.

I solved it, I put a check to see if it has hp or not

1 Like

to whom should I put as a solution that both of you helped me a lot and equally @OniiSamaUwU @HpacAm

Technically @ScriptedExpert is the first correct solution to your given and described problem, so give it to him instead.

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