I want to achieve that the variable Amount
gets past 2, the issue is that Amount
only gets past 1 and doesn’t get past 2 and i have no idea why, am i doing something wrong here?
There are no errors or any warnings, the button also keeps working after reaching 2, i honestly have no idea what could cause this issue…
Current LocalScript:
MainGui.PlayerAmount.Button.MouseButton1Click:Connect(function()
local Amount = 1
Amount += 1
if Amount > 3 then
Amount = 1
end
print("Current amount: "..Amount)
LobbyProperties.PlayerAmount = Amount
MainGui.PlayerAmount.Text = "Player amount: "..Amount
end)
I hope this issue is resolvable
You are setting the variable as 1, and then incrementing it to 2, so it will never pass the check “if Amount > 3”.
The problem is not the if statement, i can press on the button as much as i want but the number does not get any higher than 2, meaning it would never even reach 3 or above
Well this is because the scope of the variable “Amount” is within the click event, so it will never keep counting up with the same variable. Fix this by declaring the variable outside of the event.
1 Like
Oh thanks, would have never thought of that.
MainGui.PlayerAmount.Button.MouseButton1Click:Connect(function()
local Amount = 1
Amount += 1
if Amount >= 3 then
Amount = 1
end
print("Current amount: "..Amount)
LobbyProperties.PlayerAmount = Amount
MainGui.PlayerAmount.Text = "Player amount: "..Amount
end)
This might not be correct, however I believe it may be because you didn’t put ‘>=’ instead of just ‘>’ in the if statement
1 Like
>=
Means bigger than or equal but >
just means bigger than
1 Like
Sorry, I probably just read the question wrong lol.
Happy scripting!
1 Like