Hello! my name is Light (or carlover38)! I am a new developer and am trying to get started on learning the scripting side of developement, I came across something that no tutorials really went into depth about…
My goal is to create a datastore that saves the players entire backpack. My problem is that all the tutorials I find save tools individually and I want the entire backpack to save instead so that I can save other things later on that might not be tools.
Below is the basic script that I have so far:
local DataStoreService = game:GetService("DataStoreService")
local invDataStore = DataStoreService:GetDataStore("invDataStore")
--Load Data
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = invDataStore:GetAsync(playerUserId)
end)
if success then
print("Player data loaded successfully")
else
print("Player data failed to load")
warn(errormessage)
end
end)
--Save Data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = "Player"..player.UserId
local success, errormessage = pcall(function()
invDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Player data saved successfully")
else
print("Player data failed to save")
warn(errormessage)
end
end)
Any help is appreciated, thank you!