So ive added 3 stats to my game, and when adding them in it sets their value to 1, and when loading data if they have no data for those stats then its value is also set 1, yet when loading into the game the stat starts at 0
Adding the stats:
Loading data:
So if the stat is set to default at 1 when its created, and if theirs no data loaded for the player then how does it end up being 0?
(Ive also tested on a local server with multiple players to confirm its an issue, rather than having previously saved data on my account before setting the default value to 1)
The data works for every other stat and value in the game and even this one (changing it on the server to 2 and reconnecting will load 2) so I dont think the data is part of the problem
It’s a simple question. If the data doesn’t load, does it become an empty table or a nil value? If it’s an empty table then that if statement won’t run
The problem seems to be how your if statement is structured:
The first check is when the data request is successful. Therefore, any elseif conditions following that assumes that “success” is not true, yet in that elseif condition you are checking for “success” being true
You should instead immediately check for the absence of data right after confirming that the data request was successful, and go on from there
if success then
if data then
else
Also, perhaps you were supposed to do this instead:
local success, data = pcall(statstore.GetAsync, statstore, playerUserID)
if success == true then
data = data or {}
player.extrastats.XP.Value = data.xpData or 0
player.upgradestats.M4A1Damage.Value = data.M4A1DamageData or 1
...
else
print(data)
end
This looks useful to improving how its set out, but I still fail to see how the value would be set to 0? If you dont have data it should be 1, and if you do or if its not set out in a way to set it to 1 (in the elseif section), it should still be 1 as thats the value its given when its created
Even when I load in with a player who has never played before?
I thought if it was set to 0 then changed to 1 in the datastore (as it is now) then any new player would be given the new value of 1
I see thanks, I just find it weird that other stats which are set out in the exact same way (set as 1 when created, set as 1 if no data) work while this one doesnt
-- lua checks to see if success is = to true if it is then it will run code 1 but if success is not true then it will skip
if success then
-- code 1
elseif success and not data then -- if success was false and we skipped the (if success then) now lua will check this and this is saying if success is true but success will never be true becuase if it was true it would of went into code 1
-- code 2
end
its a bit hard to explain but if success is true then it will not go into else
local hairColor = "Red"
if hairColor == "Red" then
print("Its RED!!!")
else
print("Its Not RED!!!")
end
if hairColor == "Red" then
print("Its RED!!!")
elseif hairColor == "Red" then
print("???") -- this can never happen
end