How to make a Sprint Button System in Studio Lite [2026]

Опубликовано: 10 Август 2026
на канале: Studio Lite
No
0

-- Script created for Roblox Studio Lite
-- Credits to @StudioLite-v4

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

-- Settings
local NORMAL_SPEED = 16
local SPRINT_SPEED = 30
local COOLDOWN_TIME = 5

local isCooldown = false
local isSprinting = false

-- 1. Create the ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "SprintGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = playerGui

-- 2. Create the Sprint Button
local sprintButton = Instance.new("TextButton")
sprintButton.Name = "SprintButton"
sprintButton.Size = UDim2.new(0, 90, 0, 90) -- Size: 90x90 pixels

-- Position: 85% across screen (Right), 18% down from top
sprintButton.Position = UDim2.new(0.85, -10, 0.18, 0)

sprintButton.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
sprintButton.Text = "SPRINT"
sprintButton.TextColor3 = Color3.fromRGB(255, 255, 255)
sprintButton.TextScaled = true
sprintButton.Font = Enum.Font.SourceSansBold
sprintButton.Parent = screenGui

-- Make the button round
local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(0.5, 0)
uiCorner.Parent = sprintButton

-- Keep Humanoid updated on respawn
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
humanoid = character:WaitForChild("Humanoid")
end)

-- 3. Hold to Sprint Functions
sprintButton.MouseButton1Down:Connect(function()
if isCooldown or isSprinting then return end

isSprinting = true
humanoid.WalkSpeed = SPRINT_SPEED
sprintButton.BackgroundColor3 = Color3.fromRGB(0, 255, 127) -- Turns Green when sprinting
end)

sprintButton.MouseButton1Up:Connect(function()
if not isSprinting then return end

-- Reset speed
humanoid.WalkSpeed = NORMAL_SPEED
isSprinting = false

-- Cooldown active
isCooldown = true
sprintButton.BackgroundColor3 = Color3.fromRGB(150, 150, 150) -- Turns Gray during cooldown
sprintButton.Text = "WAIT..."

task.wait(COOLDOWN_TIME)

-- Cooldown finished
isCooldown = false
sprintButton.BackgroundColor3 = Color3.fromRGB(0, 170, 255) -- Turns back Blue
sprintButton.Text = "SPRINT"
end)