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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
sayer80 457 Moderation Voter
3 years ago
Edited 3 years ago

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
thx ALOT FilthyMonsterPlays 8 — 3y
Ad
Log in to vote
0
Answered by
kjljixx 42
3 years ago
Edited 3 years ago

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)
Log in to vote
0
Answered by 3 years ago

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)

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 FilthyMonsterPlays 8 — 3y

Answer this question