I want my buttons to return true or false depending on which one was clicked.
They’re in a module function but when the module function is fired, instead of waiting until they’re clicked, it returns nil and even after theyve been clicked still returns nil.
Sorry if it’s obvious, but how would I make the main function (since the whole thing is just in a module function) return true or false based on the ‘value’ variable changing?
return function()
local Connections = {}
-- Connect --
local Value = nil
table.insert(Connections, Button_1.MouseButton1Click:Connect(function()
Value = true
end))
table.insert(Connections, Button_2.MouseButton1Click:Connect(function()
Value = false
end))
-- Timer --
local Total = 3
while Value == nil and Total > 0 do
Total -= task.wait()
end
-- Disconnect --
for _, v in pairs(Connections) do
v:Disconnect()
end
return Value
end
So, the code will connect the events and wait 3 seconds (or less if you click) to return the value.
Return nil if you don’t click, basic function but you can adapt for what you need.