I am making a stamina/sprint script and I made a function that lets you go faster but its not working?
player = script.Parent.Parent.Parent while true do wait(.25) if(script.Parent.Variables.Stamina.Value < 100) then script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value + 1 script.Parent.GUI.Stamina.Text = "Stamina: "..script.Parent.Variables.Stamina.Value.."%" end end function onKeyDown(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.LeftShift then if (script.Parent.Variables.Stamina.Value > 0) then local humanoid = player.Character:FindFirstChild("Humanoid") humanoid.WalkSpeed = 25 end end end game:GetService("UserInputService").InputBegan:connect(onKeyDown)
And how would I make it to were when the key goes up, it stops the Sprint
local InputService = game:GetService("UserInputService") local Player = game:GetService("Players").LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") local IsSprinting = script.Parent.Variables.IsSprinting while IsSprinting.Value == false do if(script.Parent.Variables.Stamina.Value < 100) then IsSprinting.Value = false wait(.25) script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value + 1 script.Parent.GUI.Stamina.Text = "Stamina: "..script.Parent.Variables.Stamina.Value.."%" end end InputService.InputBegan:connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then if script.Parent.Variables.Stamina.Value > 0 then IsSprinting.Value = true Humanoid.WalkSpeed = 25 while IsSprinting.Value == true do wait(.05) script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value - 1 end end end end) InputService.InputEnded:connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then IsSprinting.Value = false Humanoid.WalkSpeed = 16 end end)