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

How do I use LoadNumber, but if the player has no load stats it sets it to "X"?

Asked by 10 years ago

How would I use LoadNumber to set a NumberValue's Value to whatever it was saved, but then if there are no Load Stats then it sets the Value to 10? I need this for my RPG system I'm coding. So far what I have:

gold.Value = plr:LoadNumber(goldKey) or 10

It does Load the value correctly, but it sets it to 0 rather than 10.

1 answer

Log in to vote
0
Answered by 10 years ago

Your way of doing this would work perfect if an empty key would return nil or false. However, if a key is empty it returns 0. So what you want to do is something more like this:

gold.Value = plr:LoadNumber("goldKey") ~= 0 and plr:LoadNumber("goldKey") or 10

The disadvantage of this is that when a user has received his 10 free coins previously but is back to 0 he or she will receive another 10 free coins. This can be prevented by adding another DP value:

gold.Value = plr:LoadBoolean("NotNew") and plr:LoadNumber("goldKey") or 10

You should remember to set the Boolean to false after you have given them the 10 free coins!

0
Okay, so I would have to insert a new BoolValue named "NotNew", and set it's value to false? How would I get it so that it would set to true once the player gets the free gold? Also, are the quotations marks after the "Load" needed, because mine worked fine without the ""s. SlickPwner 534 — 10y
0
Yes, the quotations are needed, because LoadNumber expects a string. If you do not use those it will look for a variable called goldKey which does not exist. You can save the BoolValue by doing plr:SaveBoolean("NotNew", true) juzzbyXfalcon 155 — 10y
Ad

Answer this question