local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- ========== НАСТРОЙКИ ==========
local WALK_SPEED = 16
local SPRINT_SPEED = 28
local SPRINT_KEY = Enum.KeyCode.LeftShift
local RUN_ANIMATION_ID = "rbxassetid://1234567890" -- <-- сюда свой ID
-- ===============================
local isHoldingSprint = false
local isPlayingRunAnim = false
local runAnim = Instance.new("Animation")
runAnim.AnimationId = RUN_ANIMATION_ID
local runTrack = animator:LoadAnimation(runAnim)
runTrack.Priority = Enum.AnimationPriority.Action
runTrack.Looped = true
local function updateSprint()
local isMoving = humanoid.MoveDirection.Magnitude > 0.1
if isHoldingSprint and isMoving then
-- Бежим
humanoid.WalkSpeed = SPRINT_SPEED
if not isPlayingRunAnim then
runTrack:Play(0.2)
isPlayingRunAnim = true
end
else
-- Стоим или отпустили Shift
humanoid.WalkSpeed = WALK_SPEED
if isPlayingRunAnim then
runTrack:Stop(0.2)
isPlayingRunAnim = false
end
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == SPRINT_KEY then
isHoldingSprint = true
updateSprint()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == SPRINT_KEY then
isHoldingSprint = false
updateSprint()
end
end)
-- Постоянно проверяем, двигается ли игрок
RunService.Heartbeat:Connect(function()
if isHoldingSprint then
updateSprint()
end
end)
-- При респавне
player.CharacterAdded:Connect(function(newChar)
character = newChar
humanoid = character:WaitForChild("Humanoid")
animator = humanoid:WaitForChild("Animator")
runAnim = Instance.new("Animation")
runAnim.AnimationId = RUN_ANIMATION_ID
runTrack = animator:LoadAnimation(runAnim)
runTrack.Priority = Enum.AnimationPriority.Action
runTrack.Looped = true
humanoid.WalkSpeed = WALK_SPEED
isHoldingSprint = false
isPlayingRunAnim = false
end)