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.
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!