Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

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.

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.

0

I think I get what you're trying to tell me. Thank you very much for your input.

1 answer

✓ Accepted answer

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.

1 comment

0

lol if you can't help him then don

This discussion is preserved as it was. New answers, comments, and votes are closed.