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

[Solved] Moves can only be used once even after waiting for cooldown?

Asked by
iiii676 23
4 years ago
Edited by chess123mate 4 years ago

Here is the first move script.

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false
script.Parent.MouseButton1Click:Connect(function()
    if Character.HumanoidRootPart.Anchored == false then
        if debounce == false then

            debounce = true

            if Player.leaderstats.Nature.Value == "Fire" then
                game.ReplicatedStorage.FireWall:FireServer()
            elseif Player.leaderstats.Nature.Value == "Grass" then
                game.ReplicatedStorage.GWall2:FireServer()
            elseif Player.leaderstats.Nature.Value == "Water" then
                game.ReplicatedStorage.WaWalk2:FireServer()
        wait(9)
                debounce = false
            end
            end
    end
end)

Even after waiting for the 9 seconds, I cant use the move or any other moves from this script.

Here is the second script

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false
script.Parent.MouseButton1Click:Connect(function()
        if Character.HumanoidRootPart.Anchored == false then
            if not debounce then

                debounce = true

                    if Player.leaderstats.Nature.Value == "Fire" then
                        game.ReplicatedStorage.ShootFireBall:FireServer()
                    elseif Player.leaderstats.Nature.Value == "Grass" then
                        game.ReplicatedStorage.ShootGrassBall:FireServer()
                    elseif Player.leaderstats.Nature.Value == "Water" then
                        game.ReplicatedStorage.ShootWaterBall:FireServer()
                wait(3)
                debounce = false
            end
            end
        end
end)

I dont know why, but its the same thing with this script. After using this move, the cooldown timer never goes back to false.

2 answers

Log in to vote
0
Answered by 4 years ago

i've been having the same problem to, i think its just roblox. After I wait the timer the rest of the code breaks, i have had to make whole timers to fix this such as below. Hopefully ROBLOX fixes this. The timer is just a demonstration of what i've had to do!

local Timer = {}
Timer.__index = Timer

function Timer.new()
    local self = setmetatable({}, Timer)

    self._finishedEvent = Instance.new("BindableEvent")
    self.finished = self._finishedEvent.Event

    self._running = false
    self._startTime = nil
    self._duration = nil

    return self
end

function Timer:start(duration)
    if not self._running then
        local timerThread = coroutine.wrap(function()
            self._running = true
            self._duration = duration
            self._startTime = tick()
            while self._running and tick() - self._startTime < duration do
                wait()
            end
            local completed = self._running
            self._running = false
            self._startTime = nil
            self._duration = nil
            self._finishedEvent:Fire(completed)
        end)
        timerThread()
    else
        warn("Warning: timer could not start again as it is already running.")
    end
end

function Timer:getTimeLeft()
    if self._running then
        local now = tick()
        local timeLeft = self._startTime + self._duration - now
        if timeLeft < 0 then
            timeLeft = 0
        end
        return timeLeft
    else
        warn("Warning: could not get remaining time, timer is not running.")
    end
end

function Timer:isRunning()
    return self._running
end

function Timer:stop()
    self._running = false
end

return Timer
Ad
Log in to vote
0
Answered by
iiii676 23
4 years ago

Never Mind, I actually just figured this out on my own.

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false
script.Parent.MouseButton1Click:Connect(function()
        if Character.HumanoidRootPart.Anchored == false then
            if not debounce then

                debounce = true

                    if Player.leaderstats.Nature.Value == "Fire" then
                game.ReplicatedStorage.ShootFireBall:FireServer()
                    elseif Player.leaderstats.Nature.Value == "Grass" then
            game.ReplicatedStorage.ShootGrassBall:FireServer()
                    elseif Player.leaderstats.Nature.Value == "Water" then
                game.ReplicatedStorage.ShootWaterBall:FireServer()
                end
        wait(3)
        debounce = false
        end
        end
end)

I forgot to end the if Player.leaderstats.Nature.Value == "Fire" then Lol

Answer this question