Hey, Sorry for using urgent but I need your help. My game is practisly done but I didn't do one thing: Data store. So I read some articles about and see some videos about. I have to store three IntValue: Win/Money/Medicine.
So, I see the AlvinBlox tutorial and I copy exactly the same script ( I have allowed the data in game settings :D ) and the script didn't save the cash (Studio and game) and I need to know why ?
Here is the script
local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Parent = leaderstats local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-cash") or 0 print("Data load") end) if success then cash.Value = data else print("Error while loading data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value) end) if success then print("Data saved") else print("Error while saving data") warn(errormessage) end end)
The print("Data saved") work one in a half. If you have some tips for doing that, thanks a lot ! So really thanks for answer to this topic ! :D
Use this:
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("CurrencySaveSystsem") game.Players.PlayerAdded:connect(function(plr) local leader = Instance.new("Folder", plr) leader.Name = "leaderstats" local Currency = Instance.new("IntValue", leader) Currency.Name = "Cash" Currency.Value = ds:GetAsync(plr.UserId) or 0 ds:SetAsync(plr.UserId, Currency.Value) Currency.Changed:connect(function() ds:SetAsync(plr.UserId, Currency.Value) end) end) game.Players.PlayerRemoving:connect(function(plr) ds:SetAsync(plr.UserId, plr.leaderstats.Cash.Value); end)