I’m trying to make the animation return to Roblox’s default animations (idle animation) when unequipping the tool.
When my code runs, the output prints “AnimWorked2” meaning the script executed correctly without errors, but the animation doesn’t “stop” and return to default rblx animations.
I’ve tried another method which came out with an error; but this one didn’t. I’ve scoured forums and rblx scripting documentation on trying to stop the animation or even to destroy it, but it doesn’t seem to work.
My animation I’m playing is looped and is replicated from replicated storage, then played onto the character’s animator as an “Idle” animation holding up boxing gloves.
(It’s a server script btw)
local gloveIdle = repStorage.Animations.Gloves.PresetAnimations.GloveIdle:Clone()
tool.Equipped:Connect(function()
local char = tool.Parent
if char:WaitForChild("Left Arm") ~= nil then
local weldClone = grip:Clone() -- This is welding dont worry about this
weldClone.Parent = char:WaitForChild("Left Arm")
weldClone.Part0 = weldClone.Parent
weldClone.Part1 = tool.Handle2
weldClone.C0 = weldClone.C0*CFrame.new(0,-1,0)
char:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle):Play() -- Animation Plays on character when tool is equipped.
print("AnimWorked")
end
end)
tool.Unequipped:Connect(function()
local char = tool.Parent.Parent.Name -- This is the players name unequuipping the tool
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == char then
v:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle):Stop()
print("AnimWorked2")
end
end
end)
For the animation for equipping the tool try setting the animation priority higher than the core ones, try each priority apart from the core priority because thats the same priority as the default animations and is the lowest priority.
You load the animation Here in the .Equipped connection
and then reload it when unequipping, this wont work since it creates a new AnimationTrack. Instead reference your AnimationTrack using: gloveIdle = char:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle)
I’m not quite sure if I understand. Wouldn’t that just make the code error, since the variable is being changed?
(I’m really sorry for being a pain, this is my first time handling animations )
tool.Unequipped:Connect(function()
local char = tool.Parent.Parent.Name -- This is the players name unequipping the tool
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == char then
gloveIdle:Destroy()
print("AnimWorked2")
end
end
end)
You never create a variable for gloveIdle, thats your issue. You’re creating a NEW AnimationTrack by using :LoadAnimation() inside your Unequipped connection