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
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.
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.
I think I get what you're trying to tell me. Thank you very much for your input.