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

Why can I still click an ImageButton when it is "ImageActivated"?

https://www.youtube.com/watch?v=xDRutOMUPj0&feature=youtu.be

up above is a video on what is happening

down below is a local script in an image button

local Button = script.Parent
local ImageActivated = "rbxassetid://5049442168"
local ImageNormal = "rbxassetid://4888438200"
Button.Image = ImageNormal
function OnButtonActivated()
	Button.Image = ImageActivated
 	script.Parent.Clickable = false
	delay(3, function()
		Button.Image = ImageNormal
	end)	
end

Button.MouseButton1Click:Connect(OnButtonActivated)

I do not understand why I can still click the ImageButton while it is on ImageActivated because of script.Parent.Clickable = false

I thought that line of code would make it so people could not click the image button when it was ImageActivated

1 answer

Hi! So you are only setting the Button.Image to another URL. The way you would prevent a player from clicking the same TextButton again is by setting up something called a Debounce. Your "Clickable" property will not work (I have removed that line).

That can be found here: https://developer.roblox.com/en-us/articles/Debounce

However if I were to insert it into your code it would look like this:

local Button = script.Parent
local ImageActivated = "rbxassetid://5049442168"
local ImageNormal = "rbxassetid://4888438200"
Button.Image = ImageNormal

local debounce = true

function OnButtonActivated()
    if debounce then
        debounce = false
        Button.Image = ImageActivated
        delay(3, function()
            Button.Image = ImageNormal
            debounce = true
        end)
    end 
end

Button.MouseButton1Click:Connect(OnButtonActivated)

When you want to reactivate your TextButton you would simply set the debounce to true again (As shown on line 14). You have a delay() in yours that I assume turns the button back on.

2 comments

0

This script works fine for changing the image after 3 seconds, that help appreciated. But I can still click the ImageButton when it is ImageActivated, which I do not want.

0

Don't unlock the debounce then.

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