This toggle system has been very time consuming for me to write and when you have several functions that need to use something like this, you will end up with 10 variables that are just “order2, order3, order4”
any help on writing this a little better?
local order = 1
gui.Buttons.Menu.MouseButton1Click:Connect(function()
if order == 1 then
order = 2
elseif order == 2 then
order = 1
end
end)
edit: Turns out I was accidentally calling this a debounce lol.
local enabled = false
gui.Buttons.Menu.MouseButton1Click:Connect(function()
enabled = not enabled
if enabled then
print("enabled")
else
print("disabled")
end
end)
local function menuClick()
util.tweenPos(frame, if toggle then UDim2.new(0.023, 0,0.244, 0) else UDim2.new(-0.5, 0,0.244, 0), .4)
util.tweenPos(frame2, if toggle then UDim2.new(0, 0,0.5, 0) else UDim2.new(0.002, 0,0.571, 0), .4)
task.wait(.5)
toggle = not toggle
end
Here’s an example:
local bool = true
warn(if bool then "its true" else "its false") -- either one will be printed based on the bool
If the boolean is true, it will print out “its true”, but if it’s false, it will print out “its false”. This looks way more cleaner than:
local bool = true
if bool then
warn("its true")
else
warn("its false")
end
everyone is recommending booleans when you can just make it in 1 line, here it switches the order from 1 to 2 and opposite, does what your code does, in a better way.
local order = 1
gui.Buttons.Menu.MouseButton1Click:Connect(function()
order = order ~= 1 and 1 or 2
end)
function func1()
end
function func2()
end
local order = 1
gui.Buttons.Menu.MouseButton1Click:Connect(function()
order = order ~= 1 and 1 or 2
local functionToPlay = order == 1 and func1 or func2
functionToPlay()
end)