Well, I’m not trying to do that.
Yeah but you are trying to make a custom event/function right?
Yeah?
If not, what would be the purpose of this topic?
Yeah so bindables are also used for custom events/functions, not just communicating between scripts. You can use either one.
Hm. I don’t get it?
Aren’t events like .MouseButton1Click a signal?
Look at this:
Yeah they’re, but don’t you wanna make custom signals? If you do then you can use bindables. Let me write out some code.
Why do I need to use bindables?
It’s not like I’m trying to do BindableEvent:Fire()
.
Well they’re sort of custom signals because you can name them custom things I guess, they’re the closest you can get to making a “custom signal”.
You can’t actually do this but if you wanted to check if the player is holding it down using the mousebutton1up and down event.
GuiButton.MouseButton1Down:Connect(function()
-- Fires when the player presses the left mouse button
end)
GuiButton.MouseButton1Up:Connect(function()
-- Fires when the user releases the left mouse up off the GUI button.
end)
You can also then add a bindable:Fire() if you wanted to. But bindables are really the closest you can get to making your own custom signals. You can also use custom module names which would give you the illusion of making a “custom signal”.
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.
Thanks for the help!
Why does that matter?
Anyway, good solution! Thanks very much!
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.