Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local userInputService = game:GetService("UserInputService")
- local maxStamina = 100
- local currentStamina = maxStamina
- local isSprinting = false
- local staminaBar = script.Parent:WaitForChild("StaminaBar")
- local staminaText = script.Parent:WaitForChild("StaminaText")
- local function updateStamina()
- staminaBar.Size = UDim2.new(currentStamina / maxStamina, 0, 1, 0)
- staminaText.Text = "Stamina: " .. math.floor(currentStamina)
- end
- userInputService.InputBegan:Connect(function(input, gameProcessed)
- if input.UserInputType == Enum.UserInputType.Touch and humanoid.MoveDirection.Magnitude > 0 then
- isSprinting = true
- isSprinting = true
- end
- end)
- userInputService.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.Touch then
- isSprinting = false
- isSprinting = false
- end
- end)
- game:GetService("RunService").RenderStepped:Connect(function()
- if humanoid.MoveDirection.Magnitude > 0 then
- if isSprinting and currentStamina > 0 then
- currentStamina = math.max(0, currentStamina - 0.5)
- elseif currentStamina > 0 then
- currentStamina = math.max(0, currentStamina - 0.1)
- end
- else
- currentStamina = math.min(maxStamina, currentStamina + 0.5)
- end
- updateStamina()
- end)
- updateStamina()
Advertisement
Add Comment
Please, Sign In to add comment