hey, yesterday I finished making a movement system and forgot I had speed coils. (the game has custom animations, including sprint animations.) I want to make it so when the tool is equipped, your walking animation will be changed to a run animation, and when unequipped, will change back.
local tool = script.Parent
local RunAnimation = (Insert animation location here)
local player = game.Players.LocalPlayer.Character
local track
tool.Equipped:Connect(function()
track = player.Humanoid:LoadAnimation(RunAnimation)
track.Priority = Enum.AnimationPriority.Movement
track:Play()
end)
tool.Unequipped:Connect(function()
if track then
track:Stop()
end
end)
Yes, infact here. This is my sprint script where if the player actually runs, itâll play the animation perfectly. I want this to be modified so if the player equips the tool and begins to walk, they get the speed and the walk animation plays. (Speed coil.)
local UIS = game:GetService(âUserInputServiceâ)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Anim = Instance.new(âAnimationâ)
Anim.AnimationId = ârbxassetid://10478382029â â Change the ID to your own Animation, Otherwise put 0 for no Animation.
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
local keyDown = false
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
keyDown = true
local animPlying = false
while keyDown == true do
wait(0.01)
if Character.Humanoid.MoveDirection.Magnitude > 0 and keyDown == true then
Character.Humanoid.WalkSpeed = 23 -- Change this to the running speed.
if animPlying == false then
animPlying = true
PlayAnim:Play()
end
elseif Character.Humanoid.MoveDirection.Magnitude <= 0 and keyDown == true then
Character.Humanoid.WalkSpeed = 23 -- Change this one too.
if animPlying == true then
animPlying = false
PlayAnim:Stop()
end
end
end
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
keyDown = false
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
end
local tool = script.Parent
local animation = tool:WaitForChild("Animation")
local player = game.Players.LocalPlayer
local char = player.Character
local loadAnimation = char.Humanoid:LoadAnimation(animation)
tool.Equipped:Connect(function()
loadAnimation:Play()
end)
This worked for me so if it doesnât work for you Iâm not too sure man
Remember to set the Animation Priorities and have a handle.
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local walkAnim = script:WaitForChild("Animation")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not walkAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
else
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
end
end)
And then implement this script into your tool script so itâd maybe look like
tool.Equipped:Connect(function()
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not walkAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
else
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
end
end)
end)