I have an idling cycle that happens but I need that when the clickDetector is detected it interrupts the cycle and performs something else.
What I thought would happen is that when playerInput is true, the first if statement in the bottom while loop somewhat gets reset and will see that playInput is true and fire the second if statement that is inside it (print for demonstration)
local sound01 = game.SoundService.Sounds.sound01
local Detect = game.Workspace.TEMP.ClickDetector
local playerInput = false
local idleBegin = false
Detect.MouseClick:Connect(function()
playerInput = true
end)
spawn(function()
while true do
wait()
if playerInput == true then
moduleScript.idleEnable = false
moduleScript.idleEnable = true --resets the if moduleScript.idleEnable == true statement (atleast im pretty sure it does)
repeat wait() until moduleScript.idleEnable == false
end
end
end)
while true do
wait()
if moduleScript.idleEnable == true then
if playerInput == true then
print("working") --doesnt print
repeat wait() until moduleScript.idleEnable == false
end
wait(4)
sound01:Play()
Detect.MaxActivationDistance = 0
sound01.Ended:Wait()
idleBegin = true
repeat wait() until moduleScript.idleEnable == false
else
idleBegin = false
Detect.MaxActivationDistance = 150
repeat wait() until moduleScript.idleEnable == true
end
end
This is all inside a LocalScript that is in StarterGui as I have ImageButtons that have functions which disable idleEnable in the beginning before the function and re-enable idleEnable at the end of the function.
I am using a moduleScript for idleEnable so that other scripts can enable or disable the idle cycle.
The moduleScript has idleEnable set to true.
idleBegin is connected to another if statement inside a spawn while loop above that I didn’t show as that part works fine.