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

How do i make my sword slash cooldown but not on delay?

Asked by 4 years ago

i'm end at this when i tried this script, i try to make my script cooldown and it's work but it's was delay like 2 seconds can somebody fix about this?

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=4437508277" --replace with id
local track
tool.Activated:Connect(function()
    wait(2)
    track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
    track.Priority = Enum.AnimationPriority.Action
    track.Looped = false
    track:Play()
end)
tool.Unequipped:Connect(function()
    if track then
        track:Stop()
    end
end)

1 answer

Log in to vote
1
Answered by
pwx 1581 Moderation Voter
4 years ago

Using wait(2) is not a way to create a debounce to prevent swinging once within' that time period. What you need is a BoolValue or a variable (preferably variable) in which will prevent players from swinging multiple times.

local tool = script.Parent
local debounce = false
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=4437508277" --replace with id
local track
tool.Activated:Connect(function()
    if debounce == false then -- check if debounce is false
        debounce = true -- prevent them swining for x seconds
        track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
        track.Priority = Enum.AnimationPriority.Action
        track.Looped = false
        track:Play()
        wait(2) -- how long before they can swing again
        debounce = false -- now they can swing
    end
end)
tool.Unequipped:Connect(function()
    if track then
        track:Stop()
    end
end)
0
Thanks OrewaKamidaa 40 — 4y
Ad

Answer this question