How do i make a confirm text in a gui for a limited time

i am trying to make an “are you sure?” text replacement for my textbutton but i don’t know what to use for it so if its been over x seconds it goes back to normal. i thought about tick? is there a simpler method?

local tx = script.Parent.Parent.TextButton.Text
local bgc =  script.Parent.Parent.TextButton.BackgroundColor3
local acc = script.Parent.Parent.TextButton
script.Parent.MouseButton1Click:Connect(function(a)
	wait()
	script.Parent.Parent.TextButton.Text = "ARE YOU SURE?"
	script.Parent.Parent.TextButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	wait(0.8)
	while wait(4) do -- gfv
		script.Parent.MouseButton1Click:Connect(function()
			script.Parent.Parent.Visible = false
			script.Parent.visi:FireServer()
		end)
	end
	acc.Text = tx acc.BackgroundColor3 = bgc return
end) 

about something like this is my script.

If you don’t mind using tick()'s then you could just do

local tx = script.Parent.Parent.TextButton.Text
local bgc =  script.Parent.Parent.TextButton.BackgroundColor3
local acc = script.Parent.Parent.TextButton
script.Parent.MouseButton1Click:Connect(function(a)
	wait()
	script.Parent.Parent.TextButton.Text = "ARE YOU SURE?"
	script.Parent.Parent.TextButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	wait(0.8)
	
	local Tick = tick()
	local Pressed = false
	
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Visible = false
		script.Parent.visi:FireServer()
		
		Pressed = true
	end)
	
	while tick() - Tick <= 4 do -- this loop runs for 4 seconds
		task.wait()
		
		if Pressed then -- if the button gets pressed, break out of the loop
			break
		end
	end
	
	acc.Text = tx acc.BackgroundColor3 = bgc return
end)

Also, in my opinion, using tick() to do this is the easiest way

You can use a for loop for this

script.Parent.Parent.TextButton.Text = "ARE YOU SURE?"
script.Parent.Parent.TextButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
local task = task.spawn(function()
    for i = 5, 1, -1 do
        script.Parent.Parent.TextButton.Text = "ARE YOU SURE? ("..i.." seconds left)"
        task.wait(1)
    end
    --go back to normal
end)
local connection = script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
     task.cancel(task)
     script.Parent.visi:FireServer()
end)

Keep in mind that there are probably simpler ways to do this

1 Like

all nice. i didn’t even know you can make reverse for i loops

1 Like
local tx = script.Parent.Parent.TextButton.Text
local bgc = script.Parent.Parent.TextButton.BackgroundColor3
local acc = script.Parent.Parent.TextButton

local function resetButton()
    acc.Text = tx
    acc.BackgroundColor3 = bgc
end

script.Parent.MouseButton1Click:Connect(function(a)
    acc.Text = "ARE YOU SURE?"
    acc.BackgroundColor3 = Color3.fromRGB(255, 0, 0)

    -- Disconnect any previous connections for confirm action
    if acc.confirmConnection then
        acc.confirmConnection:Disconnect()
    end
    
    -- Setup a temporary connection for confirmation
    acc.confirmConnection = acc.MouseButton1Click:Connect(function()
        script.Parent.Parent.Visible = false
        script.Parent.visi:FireServer()
        resetButton()
    end)
    
    -- Automatically reset after 4 seconds if no confirmation
    delay(4, function()
        if acc.Text == "ARE YOU SURE?" then
            resetButton()
        end
    end)
end)
1 Like

this one helped the most! ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

1 Like

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