Animation Plays when there's actual one in process

Hi there, I am Crystallityy and I am working on a Lightsaber for my game. I would like to stop the bug you may play another Animation while there’s an actual one in the process. Help would be greatly appreciated.

https://medal.tv/clips/63493151/d13371YbL6oO

Add a debounce:

local Tool = script.Parent
local Attack = Tool.Attack
local Defend = Tool.Defend
local Idle = Tool.Idle
local Walking = Tool.Walking

Tool.Activated:Connect(function()
    local Character = Tool.Parent
    local Humanoid = Character:FindFirstChild("Humanoid")
    local AnimationTrack = Humanoid.Animator:LoadAnimation(Attack)
    if AnimationTrack.IsPlaying then return end
    AnimationTrack:Play()
end)

The script you provided isn’t working, the issue is still the same.

Probably because it refreshes the AnimationTrack variable every time, my bad! Try this:

local Tool = script.Parent
local Attack = Tool.Attack
local Defend = Tool.Defend
local Idle = Tool.Idle
local Walking = Tool.Walking

local Debounce = false
local TimeOut = 2 -- Timeout in seconds

Tool.Activated:Connect(function()
	if Debounce then return end
	Debounce = true
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	local AnimationTrack = Humanoid.Animator:LoadAnimation(Attack)
	task.delay(TimeOut, function()
		Debounce = false
	end)
	
	AnimationTrack:Play()
end)
1 Like

Thanks! You helped me out of this.