local function Save(p) --Save Data-- local DataStore = game:GetService("DataStoreService"):GetDataStore(p.userId.."MHDRP_V0.0.1") local Stats1 = p.PlayerData:GetChildren() local s1 = {} for i=1,#Stats1 do local n = Stats1[i].Name s1[n] = Stats1[i].Value end DataStore:SetAsync("Stats1",s1) -- local Stats2 = p.PlayerInventory:GetChildren() local s2 = {} for iii=1,#Stats2 do local n2 = Stats2[iii].Name s2[n2] = Stats2[iii].Value end DataStore:SetAsync("Stats2",s2) -- local Stats3 = p.PlayerInventoryPerm:GetChildren() local s3 = {} for i=1,#Stats3 do local n3 = Stats3[i].Name s3[n3] = Stats3[i].Value end DataStore:SetAsync("Stats3",s3) -- End Here -- end function onPlayerEntered(newPlayer) --Clone Data-- local vs = script:WaitForChild("PlayerData"):Clone() vs.Parent = newPlayer local vs2 = script:WaitForChild("PlayerInventory"):Clone() vs2.Parent = newPlayer local vs3 = script:WaitForChild("PlayerInventoryPerm"):Clone() vs3.Parent = newPlayer --Setup Intial Data-- local Stats1 = vs:GetChildren() local S1 = {} for i=1,#Stats1 do local n = Stats1[i].Name S1[n] = Stats1[i].Value end -- local Stats2 = vs2:GetChildren() local S2 = {} for ii=1,#Stats2 do local n2 = Stats2[ii].Name S2[n2] = Stats2[ii].Value end -- local Stats3 = vs3:GetChildren() local S3 = {} for iii=1,#Stats3 do local n3 = Stats3[iii].Name S3[n3] = Stats3[iii].Value end --Get Data-- if newPlayer.Name ~= "Player" then local DataStore = game:GetService("DataStoreService"):GetDataStore(newPlayer.userId.."MHDRP_V0.0.1")-- Custom data if DataStore:GetAsync("Stats1") == nil then DataStore:SetAsync("Stats1", S1) end S1 = DataStore:GetAsync("Stats1") ---------------------------------------------------- if DataStore:GetAsync("Stats2") == nil then DataStore:SetAsync("Stats2", S2) end S2 = DataStore:GetAsync("Stats2") ---------------------------------------------------- if DataStore:GetAsync("Stats3") == nil then DataStore:SetAsync("Stats3", S3) end S3 = DataStore:GetAsync("Stats3") end --Safely Load Data-- local vv = vs:GetChildren() for i=1,#vv do local n = vv[i].Name if S1[n] ~= nil then vv[i].Value = S1[n] end end -- local vv2 = vs2:GetChildren() for i=1,#vv2 do local n2 = vv2[i].Name if S2[n2] ~= nil then vv2[i].Value = S2[n2] end end -- local vv3 = vs3:GetChildren() for i=1,#vv3 do local n3 = vv3[i].Name if S3[n3] ~= nil then vv3[i].Value = S3[n3] end end end game.Players.PlayerAdded:connect(onPlayerEntered) for _,player in pairs(game.Players:GetChildren()) do onPlayerEntered(player) end game.Players.PlayerRemoving:connect(function(p) Save(p) end)
https://gyazo.com/7d78d59c02a5770063dbbd08cbd1a711.png
Help! My datastore would save PlayerData but won't save PlayerInventory! No errors are shown, every thing is in place! No idea what's happening.
"Stat2" is what's weird, everything is cloned into the game. PlayerData and PlayerInventory are cloned into the player when they joined, and an intValue is cloned into PlayerInventory when they interact with objects.