The server script and datastore script:
local KeyData = require(script.Parent.DataSettings)
local DSS = game:GetService("DataStoreService")
local backpack = DSS:GetDataStore(KeyData.Key.."-"..KeyData.Version.."-BackpackTesting926")
local BackPackTable = {
["Item1"] = "PLACEHOLDER",
["Item2"] = "PLACEHOLDER",
["Item3"] = "PLACEHOLDER",
["Item4"] = "PLACEHOLDER",
["Item5"] = "PLACEHOLDER",
["Item6"] = "PLACEHOLDER",
["Item7"] = "PLACEHOLDER",
["Item8"] = "PLACEHOLDER",
["Item9"] = "PLACEHOLDER",
["Item10"] = "PLACEHOLDER",
["Item11"] = "PLACEHOLDER",
["Item12"] = "PLACEHOLDER",
["Item13"] = "PLACEHOLDER",
["Item14"] = "PLACEHOLDER",
["Item15"] = "PLACEHOLDER",
["Item16"] = "PLACEHOLDER",
}
local getData = function(player)
for n,v in pairs(player.Items:GetChildren()) do
return v.Value
end
end
game.Players.PlayerAdded:Connect(function(player)
local bfolder = Instance.new("Folder")
bfolder.Name = "Items"
bfolder.Parent = player
for name, value in pairs(BackPackTable) do
local new = Instance.new("StringValue")
new.Name = name
new.Value = backpack:GetAsync(player.UserId) or value
new.Parent = bfolder
end
game:GetService("ReplicatedStorage").LoadBackpack:FireClient(player, getData(player))
game.Players.PlayerRemoving:Connect(function(player)
backpack:SetAsync(player.UserId, getData(player))
end)
while wait(30) do
backpack:SetAsync(player.UserId, getData(player))
end
end)
As you can see here in the script, it's a normal datastore script with tables and an i,v in pairs function to get the player's data and return as an array. On the RemoteEvent fire is sends the player as the first parameter then the returned array as the second parameter. Backpack / client script:
local mainframe = script.Parent.MainInventory
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local grid = mainframe.Grid
local topbar = mainframe.TopBar
local box = mainframe.Box
local bottombar = mainframe.BottomBar
game:GetService("ReplicatedStorage").LoadBackpack.OnClientEvent:Connect(function(player, data)
for _,v in pairs(grid:GetChildren()) do
if v:IsA("TextButton") then
v.Text = tostring(data) or ""
v.SelectedItem.Value = tostring(data) or ""
end
end
end)
When the remoteevent is fired, it loads each grid with the player's data. Reference if you don't know what I'm talking about: https://imgur.com/3qmu6TI . However there aren't any errors and I have no idea how to fix this.
