Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Do I stop A Script From Giving Me stuff when I reach a number?

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)

`

3 answers

✓ Accepted answer

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)

1 comment

1

thx ALOT

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)

1 comment

0

sorry I Didn't explain properly Its for a shop that is selling a consumable so i want it to check if the player is full of them / maxed

This discussion is preserved as it was. New answers, comments, and votes are closed.