local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animtrack = humanoid:LoadAnimation(anim)
tool.Activated:Connect(function()
animtrack:Play()
end)
Perhaps try to load the animation only when the player uses the tool, and load the animation through the Animator object under the Humanoid? (Make sure to also change the animation’s priority to Action)
local tool = script.Parent
local anim = tool:WaitForChild("Animation")
tool.Activated:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass(“Animator”)
local animtrack = animator:LoadAnimation(anim)
animtrack:Play()
end)
Oops, I overlooked that detail. Let me rewrite my posted script above:
local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local animTrack
tool.Activated:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass(“Animator”)
animtrack = animator:LoadAnimation(anim)
animtrack:Play()
end)
tool.Unequipped:Connect(function()
animtrack:Stop()
end)
I think this should work? I don’t have access to my laptop right now
Hi, I’m so sorry for simply typing unchecked scripts! Since I now have my laptop, I was able to actually test my scripts. Make sure to also change the animation’s priority to Action! This should be a final Script:
LocalScript in tool:
local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local animtrack = animator:LoadAnimation(anim)
local isAnimationPlaying = false -- I'm assuming you don't want animations to be spammed.
tool.Activated:Connect(function()
if not isAnimationPlaying then
isAnimationPlaying = true
animtrack:Play()
print("Playing animation")
animtrack.Stopped:Wait()
isAnimationPlaying = false
end
end)
tool.Unequipped:Connect(function()
animtrack:Stop()
end)
LocalScript in ReplicatedFirst:
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local animator = character:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
character.ChildRemoved:Connect(function(child)
print("Found removed child")
if child:IsA("Tool") then
for i, animation in pairs(animator:GetPlayingAnimationTracks()) do
if animation.Priority == Enum.AnimationPriority.Action then
animation:Stop()
end
end
end
end)