local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local MAX_SPEED = 45
local ACCELERATION = 2
local BASE_SPEED = 16
local character
local humanoid
local rootPart
local currentSpeed = BASE_SPEED
local function setupCharacter(char)
character = char
humanoid = char:WaitForChild("Humanoid")
rootPart = char:WaitForChild("HumanoidRootPart")
currentSpeed = BASE_SPEED
humanoid.WalkSpeed = BASE_SPEED
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Landed then
currentSpeed = math.min(
currentSpeed + ACCELERATION,
MAX_SPEED
)
end
end)
end
player.CharacterAdded:Connect(setupCharacter)
if player.Character then
setupCharacter(player.Character)
end
RunService.Heartbeat:Connect(function()
if not humanoid or not rootPart then
return
end
humanoid.WalkSpeed = currentSpeed
end)