generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

DataStore problem

Previous Thread :: Next Thread 
Soybeen is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. hasang1
Joined: 09 Nov 2012
Total Posts: 903
19 Apr 2017 01:20 PM
Tip
{}=={} is false
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
19 Apr 2017 01:38 PM
Oh seriously? Alright


Report Abuse
hasang1 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image