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

How could i add a cooldown GUI to my Ability?

Asked by 2 years ago

Hello, im new to scripting and i'd like to ask how im supposed to add a cooldown GUI to this script. Btw the cooldown time is set to 6 seconds.

--Made By 123Marooxd123
local lleg = script.Parent:FindFirstChild("Left Leg")
local rleg = script.Parent:FindFirstChild("Right Leg")
local db = true
local UIS = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local DropAnim= Instance.new("Animation")
DropAnim.AnimationId = "rbxassetid://9661495094"

local dmg = false
local CanDropkick = false
local Keybind = Enum.KeyCode.E
local LeftLeg = game.Players.LocalPlayer.Character["Left Leg"]
local RightLeg = game.Players.LocalPlayer.Character["Right Leg"]

local topspeed = 20
character.Humanoid.Running:Connect(function(speed)
    if speed > topspeed then
        CanDropkick = true
        dmg = true
    else if speed < topspeed then
            CanDropkick = false
            dmg = false
        end
    end
end)



function dmg(hit)
    if not CanDropkick then return end
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hum.Health = hum.Health -10
        end
    end
end

lleg.Touched:connect(dmg)
rleg.Touched:connect(dmg)

UIS.InputBegan:Connect(function(input,gameprocessed)
    if gameprocessed then return end
    if not CanDropkick then return end
    if not dmg then return end
    if not db then return end
    if input.KeyCode == Keybind then
        CanDropkick = false
        dmg = true
        db = false




        local playAnim = character.Humanoid:LoadAnimation(DropAnim)

        playAnim:Play()
    local drop = Instance.new("BodyVelocity")
    drop.MaxForce = Vector3.new (1,0,1) *30000
    drop.Velocity = character.HumanoidRootPart.CFrame.lookVector * 85
    drop.Parent = character.HumanoidRootPart

        for count = 1, 8 do
    wait(0.13)
    drop.Velocity*= 0.5
        end

    playAnim:Stop()
    drop:Destroy()
        CanDropkick = true
        wait(6)
        dmg = false
        db = true
        end
    end)

1 answer

Log in to vote
0
Answered by 2 years ago

Hello!

I believe the answer is very simple. Every script has a property called "Disabled". This means that the script can not start running, but still finishes out whatever code has already been started. This is very helpful for cooldown scripts.

At the beginning of each function you have, add one line that says:

script.Disabled = true

Then, at the bottom of each function, add this:

script.Disabled = false

Here is a example of the first function, but remember that you need to do this to all of your functions.

function dmg(hit)
    script.Disabled = true -- Shuts the Script off
    if not CanDropkick then return end
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hum.Health = hum.Health -10
        end
    end
   wait(6) -- cooldown time
   script.Disabled = false -- Turns the script back on
end

I hope this helps! Let me know if you run into any problems or have any further questions! :)

~Amanda314159

0
Thank you, although I think you misunderstood my question. What im trying to make is a gui that shows you how long you have to wait before you can perform your ability 123marooxd123 13 — 2y
Ad

Answer this question