You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
To save a player’s inventory when they leave the game and rejoin. -
What is the issue? Include screenshots / videos if possible.
I don’t know how to do this… I’m very new to scripting. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked for YouTube tutorials, but they were for saving things like leaderstats. I couldn’t find any tutorials that helped me.
I want to make a script to save a players Backpack when they leave the game. I currently have a working Leaderstats saving script (from a different tutorial), but no tool-saving script.
I was thinking about saving a number (0 to 1) for each different tool: Player gets Tool1, then the Tool1 datastore is updated to 1, if/when they rejoin, then if Tool1 == 1, then it gives the player Tool1. Probably not the most efficient, but I’m new to scripting…
My current leaderstats saving script (works); if this could be modified to also save tools, that would be great!
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("WoodSaveSystem")
local ds2 = datastore:GetDataStore("StoneSaveSystem")
local ds3 = datastore:GetDataStore("IronSaveSystem")
local ds5 = datastore:GetDataStore("ExploriteSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-------------------Data Saving System-----------------------------
local Wood = Instance.new("IntValue", leaderstats)
Wood.Name = "Wood"
local Stone = Instance.new("IntValue", leaderstats)
Stone.Name = "Stone"
local Iron = Instance.new("IntValue", leaderstats)
Iron.Name = "Iron"
local Explorite = Instance.new("IntValue", leaderstats)
Explorite.Name = "Explorite"
Wood.Value = ds1:GetAsync(player.UserId) or 10
ds1:SetAsync(player.UserId, Wood.Value)
Stone.Value = ds2:GetAsync(player.UserId) or 0
ds2:SetAsync(player.UserId, Stone.Value)
Iron.Value = ds3:GetAsync(player.UserId) or 0
ds3:SetAsync(player.UserId, Iron.Value)
Explorite.Value = ds5:GetAsync(player.UserId) or 0
ds5:SetAsync(player.UserId, Explorite.Value)
-- update data saves
end)
game.Players.PlayerRemoving:Connect(function(player)
ds1:SetAsync(player.UserId, player.leaderstats.Wood.Value)
ds2:SetAsync(player.UserId, player.leaderstats.Stone.Value)
ds3:SetAsync(player.UserId, player.leaderstats.Iron.Value)
ds5:SetAsync(player.UserId, player.leaderstats.Explorite.Value)
print ("saved data")
end)