Hello!
I created a basic module that listens to multiple events but proceeds when only one fires. It works decently but the problem is that because of how .MouseButton1Up works, I had to resort to using .InputEnded but the problem is that it would work with any input, not just the mouse button. Any help?
Multi-event handler:
local module = {
['new'] = function(...)
local rbxScriptSignals = {...}
local connections = {}
local signal = Instance.new('BindableEvent')
for i,v in pairs(rbxScriptSignals) do
if typeof(v) == 'RBXScriptSignal' then
connections[#connections + 1] = v:Connect(function()
for i,v in pairs(connections) do
v:Disconnect()
end
signal:Fire()
end)
end
end
return signal.Event
end;
}
return module
Second script, a script that controls slider UI element objects.
local players = game:GetService('Players')
local userInputService = game:GetService('UserInputService')
local localPlayer = players.LocalPlayer
local multiEventHandler = require(script.Parent:WaitForChild('MultiEventHandler'))
local module = {
['CreateSlider'] = function(self, object)
local bounds = object:GetAttribute('Bounds')
local sliderBounds = object:FindFirstChild('SliderBounds')
local sliderConnections = {}
local mouse = localPlayer:GetMouse()
if sliderBounds then
local notch = sliderBounds:FindFirstChild('Notch')
if notch then
sliderBounds.MouseButton1Down:Connect(function()
local currentConnections = {}
currentConnections[#currentConnections + 1] = mouse.Move:Connect(function()
local y = mouse.Y
local topBoundary = 0
local bottomBoundary = sliderBounds.AbsoluteSize.Y
local mousePos = y - sliderBounds.AbsolutePosition.Y
notch.Position = UDim2.new(
notch.Position.X.Scale,
notch.Position.Y.Scale,
0,
math.clamp(mousePos, topBoundary, bottomBoundary)
)
end)
-- IMPORTANT PART STARTS HERE
multiEventHandler.new( -- here, it creates the multi-instance signal
userInputService.TouchEnded,
sliderBounds.MouseButton1Up
):Wait()
for i,v in pairs(currentConnections) do
v:Disconnect()
end
end)
else
return warn('No Notch for UI element',object)
end
else
return warn('No SliderBounds for UI element',object)
end
end;
}
return module
The thing is, I could go about creating a sort of “flag” system but I just wanted to know if anyone had any ideas/an easier way to go about doing it.