How do I make custom signals for example GuiButton.MouseButton1Hold?

This is actually an example. You might wanna read other posts from this topic first before you post.

Iā€™m sorry man I just wanted to help you a bit.

Oh sorry about that, I didnā€™t mean to disappoint you.

Is that sarcasm or like for real? Because I kinda canā€™t tell.

No, it isnā€™t. Iā€™m actually sorry.

Oh alright. Thanks then. I guess.

Itā€™s basically like a bindable event as mentioned by others. But to answer your question, youā€™ll want to create a table that holds references to functions that you call when you fire your event. Then just call all the functions that subscribed to that specific event when you fire it, passing any data along that you fired.

You can probably use this to handle it for you

And bindable events will work pretty much the exact same way.

If you mean anything else though, this is about the extent you can get to, but realistically itā€™s basically how roblox is doing it anyways. You canā€™t really use robloxs version directly though.

1 Like

Thanks for the help!

Why does that matter? :laughing:
Anyway, good solution! Thanks very much!

1 Like

I would simply add a variable buttonDown

local button = script.Parent

local buttonDown = false

button.MouseButton1Down:Connect(function()
	buttonDown = true
end)

button.MouseButton1Up:Connect(function()
	buttonDown = false
end)

while task.wait(1) do
	if buttonDown then
		print("Button held down")
	end
end

If you want a syntax closer to MouseButton1Hold you can make a ModuleScript

local wrappedButton = {}

local buttonDown = false

wrappedButton.MouseButton1Hold = {
	Connect = function(self, callback)
		while task.wait() do
			if buttonDown then
				callback()
			end
		end
	end,
}

function wrappedButton:BindToButton(button)
	button.MouseButton1Down:Connect(function()
		buttonDown = true
	end)

	button.MouseButton1Up:Connect(function()
		buttonDown = false
	end)
end

return wrappedButton

Then you can call it using

local wrapper = require(script.Parent.ModuleScript)

local button = script.Parent

wrapper:BindToButton(button)

wrapper.MouseButton1Hold:Connect(function()
	print("hold")
end)

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