Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 19 Apr 2017 12:32 PM |
My DataStore script is printing "loading data was a success" and "their data was loaded with no problems" for players that have never even played before, when it should print "loading data was a success" "they have no data, giving them blank data"
So I guess it's successful, but the data is either nil or {} I am testing with Player1, and I tried :SetAsync(-1,{}) from the command bar, but it still shows he has data! Am I getting the ID wrong? How can I clear this/reset it to nil without making a new datastore?
-- the code
-- PLAYER ADDED game.Players.PlayerAdded:connect(function(player) local function LoadPlayerData() local data local success, message = pcall(function() data = PlayerDataStore:GetAsync(player.UserId) end) if not success then print("ERROR: ",message) local lookAgain = rep.Events.UnfamiliarPlayer:InvokeClient(player) if lookAgain == true then-- check again after a few seconds print("they want to check for data again") wait(5) LoadPlayerData() else print("they want to play offline") PlayerData[player] = BlankPlayerStats local NoSave = Instance.new("BoolValue",player) NoSave.Name = "NoSave" end else -- if success then print("loading data was a success") if data == nil or data == {} then -- pcall passed, but if they have no data print("they have no data, giving them blank data") PlayerDataStore:SetAsync(player.UserId,BlankPlayerStats) PlayerData[player] = BlankPlayerStats else PlayerData[player] = data print("their data was loaded with no problems") end end end LoadPlayerData() -- load the player data end)
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 19 Apr 2017 12:34 PM |
I changed the DataStore and it properly printed that the player had no data attached.
I must have been resetting the keys incorrectly, can you even do that through the command bar..?
|
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 19 Apr 2017 12:39 PM |
didn't know you could reset keys lol
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 19 Apr 2017 12:41 PM |
You can't put them back to nil as far as I know but you can :SetAsync() them to whatever you want, so I just set them as {}, which is still a non-nil value. Maddening.
|
|
|
| Report Abuse |
|
|
hasang1
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 903 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
hasang1
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 903 |
|
|
| 19 Apr 2017 01:38 PM |
Mhmm Thats why I use empty tables as unique keys |
|
|
| Report Abuse |
|
|