I have been scripting a sprinting feature into my game. It works, but for some reason when switching from the walking to the sprinting animation, there is about a four second delay. here is my code.

local player = game.Players.LocalPlayer

local char = player.Character

local UserInputService = game:GetService("UserInputService")

wait(2)

while true do
	local shiftHeld = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift)
	if shiftHeld == true then
		player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://5711548678"
		player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://5711548678"
		char.Humanoid.WalkSpeed = 25
	elseif shiftHeld == false then
		player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://5711468935"
		player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://5711468935"
		char.Humanoid.WalkSpeed = 16
	end
	wait(0.01)
end

1 comment

0

make a bool, make it true, and then uhh do stuff