Why is my datastore not getting the data?
I'm sorry, I'm new to DataStores.
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local myDataStore = DataStoreService:GetDataStore( "DATA" ) |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | local leaderstats = Instance.new( "Folder" , player) |
07 | leaderstats.Name = "leaderstats" |
09 | local tokens = Instance.new( "IntValue" , leaderstats) |
10 | tokens.Name = "Tokens" |
15 | local success, errormessage pcall ( function () |
16 | data = myDataStore:GetAsync(player.UserId.. "-Tokens" ) |
19 | if success ~ = nil then |
22 | print ( "There was an error while getting your data." ) |
27 | game.Players.PlayerRemoving:Connect( function (player) |
29 | local success, errormessage = pcall ( function () |
30 | myDataStore:SetAsync(player.UserId.. "-Tokens" ,player.leaderstats.Tokens.Value) |
34 | print ( "Data succesfully saved." ) |
36 | print ( "There was an error when saving data." ) |