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

Help on conditional?

Asked by 8 years ago

I was making the sword shop. Then when I spammed the button. I went into the negative coins. I set up a conditional but it seemed to work.

if game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value >= 2000 then --do stuff end

I am on mobile so this was from Memory. The coin subtraction is fine. Going into negatives isn't.

0
There's nothing wrong with that line, as far as I can tell. Make sure everything that you meant to be is in "do stuff". nicemike40 486 — 8y

2 answers

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

I can't tell if this is the issue with only one line, but maybe you should try adding a debounce so they can't spam the button. There's probably some other issue, but I can't fix it with just that.

pressed = false

if game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value >= 2000 and not pressed then
    -- Do stuff.
    wait(1)
    pressed = true
end
0
I think you meant to put the pressed=true before the wait, and pressed=false after it. nicemike40 486 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Are you using a NumberValue? Sometimes if you keep adding to a number value it will just hit a certain point and go negative. I'd suggest using an IntValue ;o;

Answer this question