RBXScriptConnection:Suspend(time) and RBXScriptConnection:Resume()

As a roblox developer, I think it would be a very useful API feature to be able to suspend bound buttons for a period of time, then resume them later on without rewriting the whole function.

A use case for me would be my paint customization gui for example. Here’s a screenshot of what it looks like:


In the game they’ll all have different names but for demonstration purposes they’re all the same.
When the player clicks one, I have to disconnect all the others because it will break if the player double-clicks (There is a tween associated with it so it’s possible to click twice before it’s off the screen).

Here is an example of how I could use these two functions in this gui I’m working on.

A use case for the time parameter would be, for instance a button with a 3 second cooldown

local connection = Button.MouseButton1Click:Connect(function()
    Money = Money + 10
    connection:Suspend(3) -- wait 3 seconds until resuming the connection.
end)

So there you have it, my little contribution for the day :slight_smile: Share some use cases below if you’d like.

This would also make it much easier to handle functions that are not the same but stored in the same table.

8 Likes

Can’t you just use a debounce?

Yea that’s what I’m doing now but I feel like there should be a way to suspend it on a per-signal basis. Debounce also doesn’t really help too much with the method using a time parameter.

This is already achievable by disconnecting and reconnecting, or creating your own suspension implementation.

local con
function GiveMoney()
    con:Disconnect()
    Money = Money + 10
    wait(3)
   con = Button.MouseButton1Click:Connect(GiveMoney)
end

con = Button.MouseButton1Click:Connect(GiveMoney)
2 Likes

This is the type of thing that we don’t need an API for. It’s far too easy to achieve this with a simple if statement - no reason to bloat the API with it.

1 Like

Yea that’s a valid point. I just think about this every time I make a debounce, but I suppose it’s a little unnecessary. Would be good for ease of use, but I see where you guys are coming from.

I think it’s very pretty api, and I might implement it in my event module for that reason, but it’s a little difficult for me to understand the use cases

Often if something is disabled I want to still do something such as let the user know through an error notification that the action is disabled
Other times there should really be no debounces, it’s just a product of poor code design (e.g: hacky yielding)

Though, with your use case it seems like users might spam click to get money, so an error wouldn’t be desirable; graying out the button would probably be sufficient

Do you think you could provide more examples to demonstrate the usefulness?