-------------------------------------------------- -- SERVICES -------------------------------------------------- local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local LocalPlayer = Players.LocalPlayer -------------------------------------------------- -- CONFIG -------------------------------------------------- local NORMAL_SPEED = 12 local RUN_SPEED = 22 local RUN_ANIMATION_ID = "rbxassetid://87945256029788" -------------------------------------------------- -- VARIABLES -------------------------------------------------- local humanoid local runTrack local shiftHeld = false -------------------------------------------------- -- SETUP CHARACTER -------------------------------------------------- local function setupCharacter(character) humanoid = character:WaitForChild("Humanoid") humanoid.WalkSpeed = NORMAL_SPEED local animation = Instance.new("Animation") animation.AnimationId = RUN_ANIMATION_ID runTrack = humanoid:LoadAnimation(animation) runTrack.Priority = Enum.AnimationPriority.Movement end LocalPlayer.CharacterAdded:Connect(setupCharacter) if LocalPlayer.Character then setupCharacter(LocalPlayer.Character) end -------------------------------------------------- -- RENDER LOOP: handles speed + animation -------------------------------------------------- RunService.RenderStepped:Connect(function() if not humanoid then return end -- SPEED CONTROL if shiftHeld then humanoid.WalkSpeed = RUN_SPEED else humanoid.WalkSpeed = NORMAL_SPEED end -- ANIMATION CONTROL if shiftHeld and humanoid.MoveDirection.Magnitude > 0 then if runTrack and not runTrack.IsPlaying then runTrack:Play() end else if runTrack and runTrack.IsPlaying then runTrack:Stop() end end end) -------------------------------------------------- -- INPUT HANDLING -------------------------------------------------- UserInputService.InputBegan:Connect(function(input, gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.LeftShift then shiftHeld = true end end) UserInputService.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then shiftHeld = false end end) print("[Sprint] Movement-based sprint with proper release active.")