Make a tool play an animation

I’m trying to make a script that when a player equips a tool it increases their speed and makes an animation play. So far I was able to increase the player’s speed when they equip it. This is what the tool looks like:


With that in mind, this is what I want it to look like:
asdfas
Here is the script I made, but I couldn’t get it to play the animation, and stop it when they are no longer equipping it:

local p = game:GetService("Players").LocalPlayer
local char = p.Character or p.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local defaultSpeed = hum.WalkSpeed
local customSpeed = 00 

local Tool = script.Parent

Tool.Equipped:Connect(function()
hum.WalkSpeed = customSpeed
end)

Tool.Unequipped:Connect(function()
hum.WalkSpeed = defaultSpeed
end)

If you could help me out, please do. Thanks.

9 Likes

add uh local anim = hum:LoadAnimation(anim) at the top

then anim:Play() when equipped

2 Likes

I don’t know how to stop it though.

1 Like

to stop it, do anim:Stop() inside of the script.

1 Like

What @FruitySama said is correct, but assuming that you will be using this animation only if the character is underwater, you will need to use humanoid:GetStatus() to check if the status is Swimming.

hum:LoadAnimation(anim) Could I just enter the id of the animation where “anim” is?

here is a script that should fit your needs (not counting underwater you’ll have to do that yourself.):

local tool = script.Parent
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://"
local track
tool.Equipped:Connect(function()
	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)
8 Likes

Is it possible to make a player r15 when the animation plays?

sorry, I have no idea. But you can change the avatar inside of game settings.

1 Like

You can make two different animations (an r15 and r6) and play one of those animations depending on if the local player is using r6 or r15. Personally, I would just force players to use r15 in game settings as it’s far less work.

1 Like