Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with "Confirm" button detecting mouse click?

I am making a confirm button, where when you click a button it asks you to confirm, and after 3 seconds it goes back to normal. How would I detect if the player has clicked again in the 3 seconds from the first click?

script.Parent.MouseButton1Click:Connect(function()

	script.Parent.Text = "Confirm?"
	script.Parent.Parent.Info.Text = "Would you like to spend 100 Credits for 100 Time?"
	script.Parent.Parent.Info.Visible = true
        -- I think somewhere here is where it would go
	wait(3)
	script.Parent.Text = "100 Time"
	script.Parent.Parent.Info.Text = ""
	script.Parent.Parent.Info.Visible = false
end)

Thanks!

1 answer

✓ Accepted answer

Try adding a bool.

local DidAlreadyClick = false
local previous = script.Parent.Text
script.Parent.MouseButton1Click:Connect(function()
if DidAlreadyClick == false then DidAlreadyClick = true
    script.Parent.Text = "Confirm?"
    script.Parent.Parent.Info.Text = "Would you like to spend 100 Credits for 100 Time?"
    script.Parent.Parent.Info.Visible = true
        -- I think somewhere here is where it would go
    wait(3)
	DidAlreadyClick = false
	script.Parent.Text = previous
else
	script.Parent.Text = "100 Time"
   	script.Parent.Parent.Info.Text = ""
   	script.Parent.Parent.Info.Visible = false
	print("purchased")
	DidAlreadyClick = false
end
end)

Untested, tell me if it works or not. Just a simple bool for a double check.

4 comments

0

But how would I detect when the mouse was clicked after the first click, and making sure that if they click after the 3 seconds it doesn't purchase without doing the confirm thing?

0

So what I mean is when the player clicks the button, it asks them to confirm, and if they didn't click it when it said confirm it resets after 3 seconds, back to 100 time etc.

0

That is the debounce, if the debounce is true then they clicked twice

0

So if they click it again, if the debounce is true it will say script.Parent.Text = "100 time"

This discussion is preserved as it was. New answers, comments, and votes are closed.