How to disable a button click?

How to temporarily avoid a button to be clicked?

2 Likes

just delete or editout the MouseButton1Click function

2 Likes

So personally I would do this by using a variable lock. I’ll display what I mean:

local button = -- whatever/wherever your button is

local disable = false -- this variable is what will lock the click function of the button
button.MouseButton1Click:Connect(function()
    if disable then return end -- if disable is true then we immediately return from this function

    -- do stuff here
end)

This is the basic format of what I would use, you can have the script set disable to true/false whenever you please.

Hope this helped!

Bubba

2 Likes

https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

https://developer.roblox.com/en-us/api-reference/class/GuiButton

There is everything you would need to undestand how to disable button in these websites.
Othewise you can just do a if statement like @bubbavimto proposed

2 Likes

Make the button’s visibility false.

button.Visible = false

Set the MaxActivationDistance to 0

If you wanted to be memory conscious you could disconnect the event and then reconnect it when necessary.

2 Likes

That’s what I’m doing.


Just disable the script it should do the job perfectly

For @agKing_21:

This topic has already been solved with a good solution. Even the devforum prompts you to make sure you want to revive a 2 year old topic. Along with that, what you said is not a good solution.
Please check and make sure the topic hasn’t already been solved before trying to give a solution, and if you do decide to give a solution, make sure you know it is better than the already given one.


For anyone who happens to stumble upon this topic:

Do not do this. If you have a script with the button click function, you would need a whole separate script for disabling that script. If you had multiple buttons, you would need separate scripts for each of them, and it just gets messy. Ideally what OP was talking about was disabling a button within a script with other code, and just disabling that script would break the game. Use the marked solution to disable a button.

Oh sorry my apology I’m new here