I tried this script, but when I unequip the sword, it stays on the position it was when the animation ended
local tool = script.Parent -- use local variables local Player = game.Players.LocalPlayer --get the local player local isitEquipped = Player.hasWeapon tool.Equipped:Connect(function(mouse) -- :Connect not :connect, :connect is deprecated isitEquipped.Value = true local attack = tool.Parent.Humanoid:LoadAnimation(script.equipAnimation) -- script.Parent is tool so just use tool.Parent attack:Play() wait(attack.Length - 0.1) attack:AdjustSpeed(0) end) tool.Unequipped:connect(function() isitEquipped.Value = false local getName = script.Parent.Parent.Parent.Name local attack = workspace:FindFirstChild(getName).Humanoid:LoadAnimation(script.equipAnimation) local idle = workspace:FindFirstChild(getName).Humanoid:LoadAnimation(script.Idle) attack:AdjustSpeed(1) wait(0.1) attack:AdjustSpeed(1) attack:Stop() end)
How do I make it go back to the position it was before the animation?
You can use :LoadCharacter
, here is an article in wiki http://wiki.roblox.com/index.php?title=API:Class/Player/LoadCharacter.
What you are going to when to loop through the playing animations tracks and stop them.
local Humanoid = Player.Character.Humanoid local ActiveTracks = Humanoid:GetPlayingAnimationTracks() for _,v in pairs(ActiveTracks) do v:Stop() end