✓ Accepted answer
The power of arrays!
Let's assume I have a place in serverstorage that contains all the tools in the game, and I want it so when players say "Save" it saves the game. It'd look something like this
local toolsfolder = game.ServerStorage.Tools
local DataStore = game:GetService("DataStoreService"):GetDataStore("InventorySaves")
function arbitraryfunction(player,type)
if type == "Load" then
local savedtools = DataStore:GetAsync("user_"..player.UserId)
if savedtools then
print("Loaded")
for _,toolname in next, savedtools do
print(toolname)
if toolsfolder:FindFirstChild(toolname) then
toolsfolder[toolname]:Clone().Parent = player.StarterGear;toolsfolder[toolname]:Clone().Parent = player.Backpack
end
end
end
elseif type == "Save" then
print("Saved")
local toolstosave = {}
for _,tool in pairs(player.Backpack:GetChildren()) do
table.insert(toolstosave,tool.Name)
end
DataStore:SetAsync("user_"..player.UserId, toolstosave)
end
end
game.Players.PlayerAdded:connect(function(Player)
arbitraryfunction(Player,"Load")
Player.Chatted:connect(function(msg)
if msg:lower() == ("Save"):lower() then
arbitraryfunction(Player,"Save")
end
end)
end)
3 comments
Any Senpais that can handle this tricky question?
Let's see... Brain explodes
Despite the fact it might be quite a bit more difficult, you could try hosting a SQL database on a free website and having your game contact your website to save items. I highly doubt you will run out of space in your database!