DataStore not Saving?
So I'm working on a DataStore
system which loads the player's data when they join and save it when they leave or when the server shuts down. The problem is that when testing the game online, the data doesn't save
. I'm not playing with anyone so I don't know if it's the game.OnClose
function. I receive no errors
in the console too. The code is below, if you could help it would mean a lot to me.
Please take note that this isn't the full script.
01 | local datastore = game:GetService( "DataStoreService" ) |
05 | game.Players.PlayerAdded:connect( function (Player) |
06 | Setup_Leaderstats(Player) |
07 | Setup_StoreStats(Player) |
08 | LoadData(Player, Player:FindFirstChild( "leaderstats" )) |
13 | function Setup_StoreStats(Player) |
14 | local Skins = replicatedstorage.Resources:FindFirstChild( "Skins" ) |
16 | local Storage = Instance.new( "IntValue" , Player) |
17 | Storage.Name = "Storage" |
19 | local SelSkin = Instance.new( "IntValue" , Storage) |
20 | SelSkin.Name = "SelectedSkinTexture" |
22 | local Skns = Instance.new( "IntValue" , Storage) |
24 | for _,v in pairs (Skins:GetChildren()) do |
25 | if v:IsA( "IntValue" ) then |
26 | local newvalue = Instance.new( "BoolValue" , Skns) |
27 | newvalue.Name = v.Name |
32 | LoadData(Player, Skns) |
33 | LoadData(Player, Storage) |
36 | function LoadData(player, data) |
37 | local Data = datastore:GetDataStore(player.Name.. "Stats" ) |
46 | function PermanentSave(Player, data) |
48 | local Data = datastore:GetDataStore(Player.Name.. "Stats" ) |
50 | for _,i in pairs (data:GetChildren()) do |
51 | Data:SetAsync(i.Name, i.Value) |
57 | function SaveAllData(Player) |
58 | PermanentSave(Player, Player:FindFirstChild( "Storage" )) |
59 | PermanentSave(Player, Player:FindFirstChild( "Storage" ).Skins) |
60 | PermanentSave(Player, Player:FindFirstChild( "leaderstats" )) |
65 | game.Players.PlayerRemoving:connect( function (player) |
71 | game.OnClose = function () |
72 | for i,v in pairs (game.Players:GetChildren()) do |