Back to Scripts
Sprint Button and Stamina Bar v1
ScriptBlox
Universal
Free
Game: Universal Script 📌
186
Views
1
Likes
0
Dislikes
AzScripter
offline
Features
Features:
- Run button as in thumbnail
- can be exhausted
- Stamina Bar
- can customize the script
Updated:
- if the player respawns the script still works
- fixed an issue where holding the sprint button until the stamina bar runs out can still sprint if the player is still holding the button
go to my profile to get version 2.
Tags
Script Code
-- Script By @AzizAnzofficiall on Youtube
-- ScriptBlox Account @AzScripter
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local cam = workspace.CurrentCamera
local blurEffect = Instance.new("BlurEffect")
blurEffect.Size = 0
blurEffect.Parent = cam
local walkSpeed = 5
local sprintSpeed = 25
local maxStamina = 100
local staminaDrainRate = 20
local staminaRegenRate = 20
local fovSprint = 85
local fovNormal = 70
local fovExhausted = 50
local fadeSpeed = 10
local flashInterval = 0.3
local sprintButtonYOffset = 60
local stamina = maxStamina
local sprinting = false
local isFlashing = false
local isExhausted = false
local isShaking = false
local isCameraShaking = false
local currentFOVState = "normal"
local gui = Instance.new("ScreenGui")
gui.Name = "SprintSystem"
gui.ResetOnSpawn = false
gui.Parent = player:WaitForChild("PlayerGui")
local staminaBackground = Instance.new("Frame")
staminaBackground.Size = UDim2.new(0.3, 0, 0.05, 0)
staminaBackground.Position = UDim2.new(0.05, 0, 0.9, 0)
staminaBackground.BackgroundColor3 = Color3.new(0, 0, 0)
staminaBackground.BackgroundTransparency = 0.5
staminaBackground.BorderSizePixel = 0
staminaBackground.Parent = gui
local staminaFill = Instance.new("Frame")
staminaFill.Size = UDim2.new(1, 0, 1, 0)
staminaFill.BackgroundColor3 = Color3.new(1, 1, 1)
staminaFill.BorderSizePixel = 0
staminaFill.Parent = staminaBackground
local sprintBtn = Instance.new("ImageButton")
sprintBtn.Name = "SprintButton"
sprintBtn.AnchorPoint = Vector2.new(0.5, 1)
sprintBtn.BackgroundTransparency = 1
sprintBtn.Image = "rbxassetid://89190879948216"
sprintBtn.Parent = gui
local breathSound = Instance.new("Sound")
breathSound.SoundId = "rbxassetid://6814463121"
breathSound.Volume = 1
breathSound.Looped = true
local function changeFOV(target)
TweenService:Create(cam, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {FieldOfView = target}):Play()
end
local function shakeStaminaUI()
if isShaking then return end
isShaking = true
task.spawn(function()
while isShaking do
local offsetX = math.random(-5, 5)
local offsetY = math.random(-2, 2)
staminaBackground.Position = UDim2.new(0.05, offsetX, 0.9, offsetY)
task.wait(0.05)
end
end)
end
local function stopShakeStaminaUI()
isShaking = false
staminaBackground.Position = UDim2.new(0.05, 0, 0.9, 0)
end
local function shakeCamera(humanoid)
if isCameraShaking then return end
isCameraShaking = true
task.spawn(function()
while isCameraShaking do
local camX = (math.random(-2, 2) * 0.1)
local camY = (math.random(-2, 2) * 0.1)
humanoid.CameraOffset = Vector3.new(camX, camY, 0)
task.wait(0.05)
end
end)
end
local function stopShakeCamera(humanoid)
isCameraShaking = false
humanoid.CameraOffset = Vector3.new(0, 0, 0)
end
local function startFlash()
if isFlashing then return end
isFlashing = true
task.spawn(function()
while isFlashing do
staminaFill.BackgroundColor3 = Color3.new(1, 0, 0)
TweenService:Create(staminaFill, TweenInfo.new(flashInterval), {BackgroundTransparency = 0}):Play()
task.wait(flashInterval)
TweenService:Create(staminaFill, TweenInfo.new(flashInterval), {BackgroundTransparency = 1}):Play()
task.wait(flashInterval)
end
end)
end
local function stopFlash()
isFlashing = false
staminaFill.BackgroundColor3 = Color3.new(1, 1, 1)
staminaFill.BackgroundTransparency = 0
end
local function setupSprintButton()
sprintBtn.MouseButton1Down:Connect(function()
if stamina > 0 and not isExhausted then
sprinting = true
sprintBtn.Image = "rbxassetid://96892467644525"
end
end)
sprintBtn.MouseButton1Up:Connect(function()
sprinting = false
sprintBtn.Image = "rbxassetid://89190879948216"
end)
end
setupSprintButton() -- Call once to set up connections
local function initializeCharacter(newCharacter)
local humanoid = newCharacter:WaitForChild("Humanoid")
local hrp = newCharacter:WaitForChild("HumanoidRootPart")
breathSound.Parent = hrp
stamina = maxStamina
sprinting = false
isExhausted = false
stopFlash()
stopShakeStaminaUI()
stopShakeCamera(humanoid)
if breathSound.IsPlaying then
breathSound:Stop()
end
TweenService:Create(blurEffect, TweenInfo.new(1), {Size = 0}):Play()
changeFOV(fovNormal)
currentFOVState = "normal"
humanoid.WalkSpeed = walkSpeed
-- Handle death to reset on respawn
humanoid.Died:Connect(function()
sprinting = false
isExhausted = false
stopFlash()
stopShakeStaminaUI()
stopShakeCamera(humanoid)
if breathSound.IsPlaying then
breathSound:Stop()
end
TweenService:Create(blurEffect, TweenInfo.new(1), {Size = 0}):Play()
end)
return humanoid
end
local humanoid = initializeCharacter(player.Character or player.CharacterAdded:Wait())
player.CharacterAdded:Connect(function(newCharacter)
humanoid = initializeCharacter(newCharacter)
end)
RunService.RenderStepped:Connect(function()
local jumpBtn = player.PlayerGui:FindFirstChild("TouchGui")
and player.PlayerGui.TouchGui:FindFirstChild("TouchControlFrame")
and player.PlayerGui.TouchGui.TouchControlFrame:FindFirstChild("JumpButton")
if jumpBtn then
sprintBtn.Size = jumpBtn.Size
local pos = jumpBtn.AbsolutePosition
local size = jumpBtn.AbsoluteSize
sprintBtn.Position = UDim2.new(0, pos.X + size.X/2, 0, pos.Y - size.Y + sprintButtonYOffset)
end
end)
RunService.RenderStepped:Connect(function(dt)
local isMoving = humanoid.MoveDirection.Magnitude > 0.1
if isExhausted or stamina <= 0 then
sprinting = false
sprintBtn.Image = "rbxassetid://89190879948216"
end
if sprinting and stamina > 0 and isMoving and not isExhausted then
stamina = math.max(0, stamina - staminaDrainRate * dt)
humanoid.WalkSpeed = sprintSpeed
if currentFOVState ~= "sprint" then
changeFOV(fovSprint)
currentFOVState = "sprint"
end
else
humanoid.WalkSpeed = walkSpeed
if isExhausted then
stamina = math.min(maxStamina, stamina + staminaRegenRate * 0.5 * dt)
if currentFOVState ~= "exhausted" then
changeFOV(fovExhausted)
currentFOVState = "exhausted"
end
else
stamina = math.min(maxStamina, stamina + staminaRegenRate * dt)
if currentFOVState ~= "normal" then
changeFOV(fovNormal)
currentFOVState = "normal"
end
end
end
staminaFill.Size = UDim2.new(stamina / maxStamina, 0, 1, 0)
if stamina <= 0 and not isExhausted then
stamina = 0
sprinting = false
sprintBtn.Image = "rbxassetid://89190879948216"
isExhausted = true
startFlash()
shakeStaminaUI()
shakeCamera(humanoid)
if not breathSound.IsPlaying then
breathSound:Play()
breathSound.Volume = 1
end
TweenService:Create(blurEffect, TweenInfo.new(0.5), {Size = 20}):Play()
elseif isExhausted and stamina >= maxStamina * 0.5 then
isExhausted = false
stopFlash()
stopShakeStaminaUI()
stopShakeCamera(humanoid)
TweenService:Create(blurEffect, TweenInfo.new(1), {Size = 0}):Play()
end
if breathSound.IsPlaying then
if isExhausted then
breathSound.Volume = 1
else
breathSound.Volume = math.clamp(breathSound.Volume - dt * 5, 0, 1)
if breathSound.Volume <= 0 then
breathSound:Stop()
breathSound.Volume = 1
end
end
else
if isExhausted then
breathSound:Play()
breathSound.Volume = 1
end
end
local targetTransparency = (stamina >= maxStamina) and 1 or 0
staminaBackground.BackgroundTransparency = staminaBackground.BackgroundTransparency + (targetTransparency - staminaBackground.BackgroundTransparency) * dt * fadeSpeed
staminaFill.BackgroundTransparency = staminaFill.BackgroundTransparency + (targetTransparency - staminaFill.BackgroundTransparency) * dt * fadeSpeed
end)
cam.FieldOfView = fovNormal
Comments (0)
Please login to comment
Login with Discord
Loading comments...