I want it To Stop When My `NumberValue Reaches 3 but it just keeps giving me 1+
local small = script.Parent local value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value max = 3 small.MouseButton1Click:Connect(function() if value > max then --wont stop giving me +1 when I reach 3 print("+1") game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value +1 else print("max") end end)
`
I don't get why everyone who answered this overlooked this....
local value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value
^^ This here will save the value for example it is 3
The PROBLEM is when you add +1 it will still output 3, that's because the value variable wont change and you have to get it each time again.
local small = script.Parent local value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft") local max = 3 small.MouseButton1Click:Connect(function() if value.Value < max then -- you've also switched < and > print("+1") value.Value += 1 else print("max") end end)
Your code has errors such as using greater than instead of less than. The following code should work if it is in a LocalScript:
local small = script.Parent local value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value small.MouseButton1Click:Connect(function() while value<=3 do print("+1") value+=1 end print("max") end)
You can do this with a for loop and use the maxValue variable as the parameter
local small = script.Parent local value = game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value local max = 3 small.MouseButton1Click:Connect(function() for i = 1, max , 1 do game.Players.LocalPlayer.Character:WaitForChild("SmallLeft").Value += 1 end end)