Alright so I have this stamina/sprint (local) script and its not preforming like I expected... Instead of it actually letting you run, it doesn't..
- the while true do loops only runs once?
- It wont let you run and stop running?
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 true do
if(IsSprinting.Value == false) then
if(script.Parent.Variables.Stamina.Value < 100) then
wait(.25)
script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value + 1
script.Parent.GUI.Stamina.Text = "Stamina: "..script.Parent.Variables.Stamina.Value.."%"
return
end
end
end
while true do
if(IsSprinting.Value == true) then
if(script.Parent.Variables.Stamina.Value < 0) then
wait(.05)
script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value - 1
script.Parent.GUI.Stamina.Text = "Stamina: "..script.Parent.Variables.Stamina.Value.."%"
return
end
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
end
end
end)
InputService.InputEnded:connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
IsSprinting.Value = false
Humanoid.WalkSpeed = 16
end
end)

7 comments
Oh, but what about the sprint functions?
By 'sprint functions' do you mean the functions connected to the event? If so, returns aren't needed.
only use returns to 'Return' a value ex: func(val) return val+1 end print(func(0))
No, the function after the while true do
Those were the functions I was talking about.
Oh how would I fix them?
'return' can also be used to return from a function's body prematurely, without returning values.