how can I change my local script to fit this datastore?
I'm pretty sure this is the problem.
I made a datastore script that goes like this:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local MyDataStore = DataStoreService:GetDataStore( "myDataStore" ) |
05 | game.Players.PlayerAdded:Connect( function (player) |
07 | local leaderstats = Instance.new( "Folder" ) |
08 | leaderstats.Name = "leaderstats" |
09 | leaderstats.Parent = player |
12 | local cash = Instance.new( "IntValue" ) |
14 | cash.Parent = leaderstats |
21 | local success, errormessage = pcall ( function () |
23 | data = MyDataStore:GetAsync(player.UserId.. "-cash" ) or 0 |
41 | game.Players.PlayerRemoving:Connect( function (player) |
42 | local success, errormessage = pcall ( function () |
43 | MyDataStore:SetAsync(player.UserId.. "-cash" ,player.leaderstats.Cash.Value) |
46 | if success then print ( "Data Saved" ) |
If I play my game on Roblox (not studio)
I am able to save the value of cash if I type a command from HD admin.
I leave the game and this is saved and remains when I come back.
However, I have a localscript in StarterPlayerScripts that is:
3 | game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 10 |
The 1000 will go (ex.1040) and it won't save.
I can use the admin command to change the value to 1040 and it saves.
What can I do to fix this?