Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the timer stop when clicked again?

Asked by 3 years ago
Edited 3 years ago

I have a function that starts the timer, but for some reason I can't make it stop with the "break" command. No errors either.

local Use
local Active = true
local InCloak = true
local StopTimer = true
local UseingCloak = script.Parent.IsCloak
local DoneCloaking = script.Parent.DoneCloak
local Timer = script.Parent.CloakTimer
local Count = script.Parent.CountUp


script.Parent.Activated:Connect(function()
    if Timer.Value <= 10 then
    else
    if Active == true then
        coroutine.resume(coroutine.create(function()
            Active = false
                wait(2)-- Delay
                StopTimer = true
            UseingCloak.Value = true
            Count.Value = false
            script.Parent.Handle.Cloak:Play()
            wait(1)
            InCloak = true

            if InCloak == true then
                InCloak = false
                Active = true
            end


        end))

    elseif InCloak == true then
        InCloak = false

            wait(2)--Delay
            StopTimer = false
        -- Uncloak
        script.Parent.Handle.UnCloak:Play()
        Count.Value = true
        wait(1) -- general tool cooldown
            Active = true
        end
    end
end)


function calculate() -- Timer Countdown
    if UseingCloak.Value == true then
        while true do
            wait(.5)
            Timer.Value -= 1
            if Timer.Value <= 0 then -- This doesn't stop
                script.Parent.Handle.UnCloak:Play()
                InCloak = false
                Count.Value = true
                Active = true
                break
            elseif StopTimer == false then  -- This doesn't stop
                StopTimer = false
                script.Parent.Handle.UnCloak:Play()
                InCloak = false
                Count.Value = true
                Active = true
                break
            end 
        end
    end
end

function calculate2() -- Timer Regen
    if Count.Value == true then
        while true do
            wait(.1)
            Timer.Value += 0.1
            if UseingCloak.Value == true then
                break
            end
            if Timer.Value >= 60 then
                Timer.Value = 60
                if Timer.Value <= 0 then
                    Timer.Value = 0
                end
            end
        end
    end
end

UseingCloak:GetPropertyChangedSignal("Value"):Connect(calculate)
DoneCloaking:GetPropertyChangedSignal("Value"):Connect(calculate)
Count:GetPropertyChangedSignal("Value"):Connect(calculate)
0
Try using print() statements. They help alot. Soban06 410 — 3y

Answer this question