Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----- SHIFT TO RUN SCRIPT WITH STAMINA ------
- -- Server Script
- local realSprintScript = script:FindFirstChild("RealSprintScript")
- if realSprintScript and game:GetService("StarterGui") then
- local clonedScript = realSprintScript:Clone()
- clonedScript.Parent = game:GetService("StarterGui")
- end
- -- Local Script
- repeat wait() until game.Players.LocalPlayer
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local UserInputService = game:GetService("UserInputService")
- local VRService = game:GetService("VRService")
- local walkSpeed = 16
- local runSpeed = 24
- local maxStamina = 100
- local currentStamina = maxStamina
- local staminaDrain = 10
- local staminaRegen = 5
- local function createStaminaBar()
- local screenGui = Instance.new("ScreenGui")
- local frame = Instance.new("Frame")
- local bar = Instance.new("Frame")
- local frameUICorner = Instance.new("UICorner")
- local barUICorner = Instance.new("UICorner")
- screenGui.Name = "StaminaBarGui"
- screenGui.Parent = player:WaitForChild("PlayerGui")
- frame.Name = "StaminaFrame"
- frame.Size = UDim2.new(0, 200, 0, 25)
- frame.Position = UDim2.new(0, 10, 1, -35)
- frame.BackgroundColor3 = Color3.new(0, 0, 0)
- frame.BorderSizePixel = 0
- frame.Parent = screenGui
- frameUICorner.CornerRadius = UDim.new(0, 10)
- frameUICorner.Parent = frame
- bar.Name = "StaminaBar"
- bar.Size = UDim2.new(1, -4, 1, -4)
- bar.Position = UDim2.new(0, 2, 0, 2)
- bar.BackgroundColor3 = Color3.new(0, 0.8, 0)
- bar.BorderSizePixel = 0
- bar.Parent = frame
- barUICorner.CornerRadius = UDim.new(0, 8)
- barUICorner.Parent = bar
- return bar
- end
- local staminaBar = createStaminaBar()
- local function updateStamina(deltaTime)
- if humanoid.WalkSpeed == runSpeed then
- currentStamina = math.max(0, currentStamina - staminaDrain * deltaTime)
- else
- currentStamina = math.min(maxStamina, currentStamina + staminaRegen * deltaTime)
- end
- staminaBar.Size = UDim2.new(currentStamina / maxStamina, -4, 1, -4)
- if currentStamina <= 0 then
- humanoid.WalkSpeed = walkSpeed
- end
- end
- local function setRunSpeed(isRunning)
- if isRunning and currentStamina > 0 then
- humanoid.WalkSpeed = runSpeed
- else
- humanoid.WalkSpeed = walkSpeed
- end
- end
- local function createRunButton()
- local screenGui = Instance.new("ScreenGui")
- local button = Instance.new("TextButton")
- screenGui.Name = "RunButtonGui"
- screenGui.Parent = player:WaitForChild("PlayerGui")
- button.Name = "RunButton"
- button.Text = "Sprint"
- button.TextColor3 = Color3.new(1, 1, 1)
- button.BackgroundColor3 = Color3.new(0, 0.5, 1)
- button.Size = UDim2.new(0, 150, 0, 50)
- button.Position = UDim2.new(0.85, -75, 0.5, -25)
- button.Font = Enum.Font.SourceSansBold
- button.TextSize = 24
- button.BorderSizePixel = 0
- button.Parent = screenGui
- local uiCorner = Instance.new("UICorner")
- uiCorner.CornerRadius = UDim.new(0, 12)
- uiCorner.Parent = button
- local isRunning = false
- button.MouseButton1Down:Connect(function()
- isRunning = true
- setRunSpeed(isRunning)
- end)
- button.MouseButton1Up:Connect(function()
- isRunning = false
- setRunSpeed(isRunning)
- end)
- end
- if UserInputService.TouchEnabled then
- createRunButton()
- end
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.UserInputType == Enum.UserInputType.Keyboard then
- if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
- setRunSpeed(true)
- end
- elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
- if input.KeyCode == Enum.KeyCode.ButtonL3 then
- setRunSpeed(true)
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.UserInputType == Enum.UserInputType.Keyboard then
- if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
- setRunSpeed(false)
- end
- elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
- if input.KeyCode == Enum.KeyCode.ButtonL3 then
- setRunSpeed(false)
- end
- end
- end)
- game:GetService("RunService").RenderStepped:Connect(updateStamina)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement