I’m trying to add a sprinting animation when the player is sprinting. Here’s my code:
local mouse = game.Players.LocalPlayer:GetMouse()
local running = false
function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end
mouse.KeyDown:connect(function (key) -- Run function
key = string.lower(key)
if string.byte(key) == 48 then
running = true
local keyConnection = mouse.KeyUp:connect(function (key)
if string.byte(key) == 48 then
running = false
end
end)
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*1.2))
wait()
end
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 32
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://12519622959'
local PlayAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
for _, child in pairs(script.Parent.HumanoidRootPart:GetChildren()) do
if child:IsA("Sound") then
child.PlaybackSpeed = 1.5
task.wait()
script.Parent.HumanoidRootPart.Jumping.PlaybackSpeed = 1
end
end
repeat wait () until running == false
keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (73-(i*1.2))
wait()
end
for _, child in pairs(script.Parent.HumanoidRootPart:GetChildren()) do
if child:IsA("Sound") then
child.PlaybackSpeed = 1
end
end
end
end)
The problem is that when the player is sprinting, 2 animations are trying to play at the same time.
Please let me know how to fix this, thanks!