But u can make a bool value for each item. And when the player is leaving u can check what the player currently has in their inventory and check the bool values for that item. Then u can save the bool values. Then when the player is added u can see what bools r true and add back whatever items r true.
Maybe try this one: Open Sourced Inventory/Backpack system
I haven’t used it myself but u can give it a try. Also u can try searching up on how to make ur own inventory system and there r many YT vids and dev forum posts on it.
i dont think i have elaborated myself enough, so apologies for the lack of information.
i am trying to make a custom inventory system, so when the player clicks on a part, it saves inside the inventory after its destroyed. the parts are being spawned from a module script. and when the player leaves the game, it saves all the collected parts for the player so that when they rejoin, it reloads it back for them.
yeah thats my clarification, hope this gives more context to my question
While I have never made a proper inventory system myself, I can say the solution PIZZA came up with by saving a bool and perhaps an int aswell should make this work easily.
Simply make the guis and stuff, make a bool for every item you have and add an int value to check the amount you have if you plan to allow multiple copies in the inventory.
Bool and Int values can be saved through DataStorage so whenever you load/deload you just add the gui for the items in question back into the game when joining.
Put a clickdetector or something similar in the part you want to collect and have that detector modify the preset values for that item which then automatically adds it into the inventory because of the refresh you have on it (refresh it every 1-5 seconds to accommodate for change).
With the information you have been provided you can start tinkering around to make a system like what you are aiming for, you just have to try it out now.
hope some of that helped and cleared up some stuff.
You need DataStorage to make this system, the server itself cannot save your data for you.
You will need to have Values add the item gui parts automatically upon joining in the scenario that you may own one of the items.
Save the values you have for owning the item and the potential quanitity owned inside tables for datastorage to save, then load that data upon joining the game again.
I encourage you to look into how datastorage works incase you may not already know how it works.
You might not be able to save values directly to datastores but you can save an array/table.
Pretty sure I already said that you can’t save instances to datastores, thats why you have to put it into an array or table to save it to Datastorage.
My implied method saves a value, like an ID of the item tied to the bool which checks if you own it or not to datastorage which I have done before and has worked just fine.
im honestly kinda new to scripting, and i dont know how to code the system. are there any posts or yt videos i can follow to achieve my goal? (it would be recommended if the post/video made use of a base part)
local tools = --folder that should be located in ReplicatedStorage called Tools (included image shows how it should look)
local key = game:GetService("DataStoreService"):GetDataStore("name it whatever")
game.Players.PlayerAdded:Connect(function(plr)
if key:GetAsync(plr.UserId) ~= nil then
for i,v in key:GetAsync(plr.UserId) do
if tools:FindFirstChild(v) then
local tool = tools[v]:Clone()
tool.Parent = plr.Backpack
else
warn(debug.traceback("Tool not found."))
end
end
print("Loaded tools!")
else
print("New user - data is nil")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local tool_table = {}
for i,v in pairs(plr.Backpack:GetChildren()) do
table.insert(tool_table, v.Name)
end
key:SetAsync(plr.UserId, tool_table)
print("Saved tools!")
end)