Why doesn't it save the data in this dataStore script?
I'm making a data store script and I can't seem to see an error. There is no error in the output either. Here is my script, pls fix if possible.
01 | local DSS = game:GetService( "DataStoreService" ) |
02 | local cashDSS = DSS:GetDataStore( "CurrencyStore" ) |
04 | game.Players.PlayerAdded:Connect( function (plr) |
06 | local leaderstats = Instance.new( "Folder" ,plr) |
07 | leaderstats.Name = "leaderstats" |
09 | local Currency = Instance.new( "IntValue" , leaderstats) |
10 | Currency.Name = "Bucks" |
14 | local success, errormsg = pcall ( function () |
15 | data = cashDSS:GetAsync(plr.UserId.. "-Bucks" ) |
20 | print ( "data of " ..plr.Name.. " has been loaded" ) |
24 | print ( "Data of " ..plr.Name.. " couldn't be loaded" ) |
30 | game.Players.PlayerRemoving:Connect( function (plr) |
31 | local success, errormsg = pcall ( function () |
32 | cashDSS:SetAsync(plr.UserId.. "-Bucks" , plr.leaderstats.Bucks.Value) |
36 | print ( "Successfully saved data of " ..plr.Name) |
38 | print ( "Data could not be saved of " ..plr.Name) |
I appreciate your time and effort. Thanks for helping.