What does the code do?
The code makes an animation play when the tool is equipped
What potential improvements have you considered?
I tried using Enum.HumanoidStateType but that didnt work
How (specifically) do you want to improve the code?
I would like the code to make an animation play when you are moving and have the tool equipped
local player = game.Players.LocalPlayer
repeat wait(1) until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local idle = script.Idle
local move = script.Move
local idletrack = humanoid:LoadAnimation(idle)
local movetrack = humanoid:LoadAnimation(move)
script.Parent.Equipped:connect(function()
idletrack:Play()
end)
script.Parent.Unequipped:connect(function()
idletrack:Stop()
end)
You can go into the character and there will be an Animate script and you just change the animation id under it where it says walk to the walk animation and when you unequip the item you can just change the animation id back to the old one.
local player = game.Players.LocalPlayer
repeat wait(1) until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local idle = script.Idle
local move = script.Move
local idletrack = humanoid:LoadAnimation(idle)
local movetrack = humanoid:LoadAnimation(move)
local Animate = character:FindFirstChild("Animate")
local OldWalkID = Animate.walk.WalkAnim.AnimationId
local OldIdleID = Animate.idle.Animation1.AnimationId
script.Parent.Equipped:connect(function()
Animate.idle.Animation1.AnimationId = idle.AnimationId
Animate.idle.Animation2.AnimationId = idle.AnimationId
Animate.walk.WalkAnim.AnimationId = move.AnimationId
end)
script.Parent.Unequipped:connect(function()
Animate.idle.Animation1.AnimationId = OldIdleID
Animate.idle.Animation2.AnimationId = OldIdleID
Animate.walk.WalkAnim.AnimationId = OldWalkID
end)