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