#Datastore help
1 messages · Page 1 of 1 (latest)
function PlayerSave(Player)
local DataStore = game:GetService("DataStoreService")
local PlayersData = DataStore:GetDataStore("Players_"..game.ServerStorage.WorldID.Value)
local HttpService = game:GetService("HttpService")
local backpack = game.ReplicatedStorage.Backpacks[Player.Name]
-- Save Backpack
local addeddata = {
Backpack = {},
Stats = {},
}
for i,v in pairs(backpack:GetChildren()) do
if not v:HasTag("NonLinearTool") then
table.insert(addeddata.Backpack,v.Name)
addeddata.Backpack[v.Name] = v:GetAttribute("Amount") or 1
end
if v:HasTag("NonLinearTool") then
if v:FindFirstChild("EncodedString") then
table.insert(addeddata.Backpack,v:FindFirstChild("EncodedString").Value)
end
end
end
-- Actually save the added data
local data = HttpService:JSONEncode(addeddata)
PlayersData:SetAsync(Player.UserId, data)
print(addeddata)
print(HttpService:JSONDecode(data))
end```
yeah nvm it works now