Hello i am trying to make a button temporary stop a function.
so basically i want that if the player clicks the playbtn, it waits for 10 secs and it makes the option visible but if the player clicked the exit play, it shouldn’t wait for 10 secs and make the option visible or anything in that function. i tried using Disconnect() but it diconnects it forever.
make sure to NOT add the local when you are just undisconnecting it. only use local when creating the variable, AKA when you are connecting it for the first time in the script.
local canPlayfunc = true
local playfunc = playbtn.MouseButton1Click:Connect(function()
if not canPlayfunc then
return
end
play.btnVisible = false
wait(10)
options.Visible = true
end)
exitplay.MouseButton1Click:Connect(function()
menu.Visible = false
canPlayfunc = false
end)
local playfunc = playbtn.MouseButton1Click:Connect(function()
play.btnVisible = false
wait(10)
if menu.Visible == false then return end
options.Visible = true
end)
or
local debounce = false
local playfunc = playbtn.MouseButton1Click:Connect(function()
if debounce then return end
debounce = true
play.btnVisible = false
local count = 0
while menu.Visible do
if count >= 10 then
options.Visible = true
break
end
count += 1
task.wait(1)
end
debounce = false
end)
i know. i dont think you understand what i want, i wanted to make it that if the the exit is clicked, it doesn’t wait for 10 secs and make options visible. Kinda want it to stop the function temporary
local canPlayfunc = true
local playfunc = playbtn.MouseButton1Click:Connect(function()
if not canPlayfunc then
return
end
play.btnVisible = false
options.Visible = true
end)
exitplay.MouseButton1Click:Connect(function()
menu.Visible = false
canPlayfunc = false
end)
If you want the exit button to make an options section/page visible then simply add “options.Visible = true” to the code. You’ll need the variable named “options” to refer to the correct UI element. Could you provide a screenshot of how everything is organised in StarterGui?
You can make use of coroutines which can be yielded and resumed whenever you want it to:
local stop = false
local coro = coroutine.create(function()
-- Code here
if stop then
coro.yield() -- Pauses the function
end
end)
coro.resume() -- Resumes the function