repeat wait() until game.Players.LocalPlayer local running = false m = game.Players.LocalPlayer:GetMouse() m.KeyDown:connect(function(key) if key == "0" and running == false then print("Running") running = true game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 22 while running == true do game.StarterGui.run.Value.Value = game.StarterGui.run.Value.Value - 1 local amount = game.StarterGui.run.Value.Value print (amount) wait(0.1) end end end) m.KeyUp:connect(function(key) if key == "0" and running == true then running = false local amount = game.StarterGui.run.Value.Value game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 11 while running == false and not amount == 100 or amount < 100 do local amount = game.StarterGui.run.Value.Value game.StarterGui.run.Value.Value = game.StarterGui.run.Value.Value + 1 print(amount) wait(0.9) end end end)
You should probably use math.clamp for stuff like this. math.clamp makes it not go below the minimum or go above the maximum.
game.StarterGui.run.Value.Value = math.clamp(game.StarterGui.run.Value.Value + 1, 0, 100) The 0 is the minimum and the 100 is the maximum.
Your while conditions statement seems contradictory if its both checking that the value is not 100 anyways or under, remove the ‘not value == 100 or’, also you are doing an infinite loop each time you run a keyUp event function which will run it multiple times infinitely (likely why it goes up over 100), try to use a repeat loop. Also, you should be using UserInputService now instead of key events of mouse.
The other answer says you can use math.clamp
which is an option as well if you want to use it.