I have a modulescript with code for moving a switch, and it has a debounce. The problem is that I need it to return the switch position (bool) THEN wait 5 seconds to reset the debounce. Return ends the function there, so how can I do this?
Main script:
_G.Reactor_Coolant_LoopInletValue = false
switch_loopinlet.ClickPart.ClickDetector.MouseClick:Connect(function()
local res = inputModule.SwitchMove(switch_loopinlet)
_G.Reactor_Coolant_LoopInletValue = res
end)
inputModule:
function module.SwitchMove(model)
local db = model.db
local val = model.val
local tweeninfo = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
if db.Value == true then return end
db.Value = true
if val.Value == false then
val.Value = true
model.Sounds.Sound:Play()
ts:Create(model.Hinge,tweeninfo,{CFrame = model.OnPos.CFrame}):Play()
else
val.Value = false
model.Sounds.Sound:Play()
ts:Create(model.Hinge,tweeninfo,{CFrame = model.OffPos.CFrame}):Play()
end
--return val.Value
wait(5)
db.Value = false
end