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

KeyDown sprint function not working?

Asked by 8 years ago

I am making a stamina/sprint script and I made a function that lets you go faster but its not working?

01player = script.Parent.Parent.Parent
02while 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
08end
09 
10function 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
17end
18game:GetService("UserInputService").InputBegan:connect(onKeyDown)

And how would I make it to were when the key goes up, it stops the Sprint

0
Sorry I don't have time to answer this, but I can give you something that will help. Here's a video I made on it: https://www.youtube.com/watch?v=9bggLpCFMOg, and the module: https://www.roblox.com/Custom-events-library-Create-or-modify-events-item?id=398814042 ScriptGuider 5640 — 8y
0
Please look at my answer below I provided, It adds to the stamina, but It wont increase my speed dotProgram 0 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
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
06 
07while 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
14end
15 
View all 34 lines...
Ad

Answer this question