Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make sprinting operate on a "stamina meter"?

Asked by 6 years ago

I've got a bit of code that enables the user to press shift to run even faster, jump higher, and leave behind a trail. How would I make this operate on a "stamina meter" value so that for the time they're moving and holding shift a value depletes?

Here's what I've got.

super_sprint = 48
dash_jump = 90

MyMouse = game.Players.localPlayer:GetMouse()
Player = game.Players.localPlayer
trail = Player.Character.HumanoidRootPart:FindFirstChild("Trail")

MyMouse.KeyDown:connect(function(key)
    if (key:byte() == 48) then
        local human = Player.Character:FindFirstChild("Humanoid")
        human.WalkSpeed = super_sprint
        human.JumpPower = dash_jump
        trail.Enabled = true
        end
end)

MyMouse.KeyUp:connect(function(key)
    if (key:byte() == 48) then
        local human = Player.Character:FindFirstChild("Humanoid")
        human.WalkSpeed = 32
        human.JumpPower = 75
        trail.Enabled = false
        end
end)
1
KeyDown is deprecated - use ContextActionService or UserInputService. Also, if you know the size of your stamina bar, you can divide it by 100 to create increments. Then based on stamina remaining you can tween the GuiObject to represent that specific interval. SummerEquinox 643 — 6y
1
For instance - let x represent stamina remaining out of 100. If x = 70 then the required interval is totalsize/100 * 70 - then you can tween to that position and size. This is how I've always done it at least. SummerEquinox 643 — 6y
0
I think I get what you're trying to tell me. Thank you very much for your input. NEXIUS10 13 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

I believe I have an answer for this. If it doesn't meet requirements please let me know.

I have to use a FOR loop otherwise incrementing values would be cumbersome.

How it works:

for i = 1, maxStam do
--maxStam is a variable that contains the **STAMINA OF THE INDIVIDUAL** please read on

stam = i
end

I know this isn't a lot but it will work if you use it wisely. Goodbye.

0
lol if you can't help him then don HappyTimIsHim 652 — 6y
Ad

Answer this question