Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.