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

Stamina/Sprint function not working properly? Any Ideas?

Asked by 8 years ago
Edited 8 years ago

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.. 1. the while true do loops only runs once? 2. It wont let you run and stop running?

01local InputService = game:GetService("UserInputService")
02local Player = game:GetService("Players").LocalPlayer
03local Character = Player.Character or Player.CharacterAdded:wait()
04local Humanoid = Character:WaitForChild("Humanoid")
05local IsSprinting = script.Parent.Variables.IsSprinting
06while true do
07    if(IsSprinting.Value == false) then
08        if(script.Parent.Variables.Stamina.Value < 100) then
09        wait(.25)
10        script.Parent.Variables.Stamina.Value = script.Parent.Variables.Stamina.Value + 1
11        script.Parent.GUI.Stamina.Text = "Stamina: "..script.Parent.Variables.Stamina.Value.."%"
12        return
13        end
14    end
15end
View all 41 lines...

1 answer

Log in to vote
0
Answered by
Versimn 20
8 years ago

You put a return in the while loops, ending them once reached. Just take them out and it should run fine

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

Answer this question