A bug in my script i can't seem to understand why it happens, why?
in short, i made a script that lets you run when pressing shift, and lets you walk when you let go.
you are able to run when an Intvalue is more than 0, and it increases every second by 1 when not running.
However, if you press shift two times under a second, the intvalue increases by 1 TWICE every second. from my understanding , the script malfunctions and runs the same line twice.
(the main bug starts at line 30)
01 | repeat wait() until game.Players.LocalPlayer |
03 | local amount = game.StarterGui.run.Value.Value |
05 | local function stoprunning() |
06 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 11 |
09 | m = game.Players.LocalPlayer:GetMouse() |
12 | m.KeyDown:connect( function (key) |
13 | if key = = "0" and running = = false then |
16 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 22 |
17 | while running = = true do |
18 | game.StarterGui.run.Value.Value = math.clamp(game.StarterGui.run.Value.Value - 1 , 0 , 100 ) |
19 | local amount = game.StarterGui.run.Value.Value |
23 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 11 |
30 | m.KeyUp:connect( function (key) |
31 | if key = = "0" and running = = true then |
33 | local amount = game.StarterGui.run.Value.Value |
34 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 11 |
35 | while running = = false do |
36 | local amount = game.StarterGui.run.Value.Value |
37 | game.StarterGui.run.Value.Value = math.clamp(game.StarterGui.run.Value.Value + 1 , 0 , 100 ) |