Help to fix animation script

hello everyone, I created a script for the animation of the blow I have a problem, namely, when I click on the blows, you can see for yourself on the video help fix my script

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://14717519545"
local track

tool.Activated:Connect(function()
	wait() -- DELAY TIME 2 SECONDS YOU CAN CHANGE IT
	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)

robloxapp-20230918-1507379.wmv (966.3 KB)

https://youtu.be/b76Zphe-aRk the link

Is there any errors in the output console? Is it your animation?

sorry for the lags, roblox studio itself is lagging, I don’t know why

yea is my animation in roblox studio

I saw the video, and I dont understand the problem, its working fine is it not?

like when I shake my hand, well, that is, I swing the force, I do it quickly if you want, I’ll give you a link to the game, test it yourself

Try this

local debounce = false
...
tool. Activated:Connect(function()
wait()
if debounce then return end
debounce = true
...
track:Play()
track.Stopped:Wait()
debounce = false

where to write this script I do not know just

Summary

first of all from the script you have provide above

tool.Activated:Connect(function()
	wait() -- DELAY TIME 2 SECONDS YOU CAN CHANGE IT
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = false
	track:Play()
end)

the above script won’t wait just beacuse you use wait inside the function
because everytime the remote event gets fired the function will called and do it task
for this use debounce
like

local debounce=false
tool.Activated:Connect(function()
	if debounce then
          return
    end
    debounce=true
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = false
	track:Play()
    wait(5)
    debounce=false
end)

nvm it will wait for few sec before the animation plays

thanks it works can you help me with another script it’s the same I just want to add a delay

local IdleAnim = Instance.new("Animation")
IdleAnim.AnimationId = "rbxassetid://14813772308"
local firstTrack 
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://13383682135"
local track
local character

tool.Equipped:Connect(function()
	firstTrack = script.Parent.Parent.Humanoid:LoadAnimation(IdleAnim)
	firstTrack.Priority = Enum.AnimationPriority.Action
	firstTrack.Looped = false
	firstTrack:Play()
	character = tool.Parent
	character.Humanoid.WalkSpeed = 0
	character.Humanoid.JumpPower = 0
	wait(1)
end)

tool.Activated:Connect(function()
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track.Looped = false
	track:Play()
	wait(1)
end)

tool.Unequipped:Connect(function()
	if firstTrack then
		firstTrack:Stop()
		character.Humanoid.WalkSpeed = 16 -- the default speed
		character.Humanoid.JumpPower = 50 -- the default jump power
	end
end)

tool.Unequipped:Connect(function()
	if track then
		track:Stop()
		character.Humanoid.WalkSpeed = 16 -- the default speed
		character.Humanoid.JumpPower = 50 -- the default jump power
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.