Add Data Store function to Inventory

Hi everyone I’m currently working on an Inventory System and it saves the Tools when I die(cuz I have set reset on Spawn to false) but when I leave and join again the Tools disappear(not sure if I should show a photo of that)
Now what I need is a Data Store function and I have no Idea how to do that but I believe it’s easy(I searched on other Platforms for the Solution but it wasn’t exactly what I needed I got 2 Scripts here:

--InventoryScript:

local inventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent

game.Players.PlayerAdded:Connect(function(player)
	
	local inventory = player:WaitForChild("Inventory")
	
	local inventoryFrame = player.PlayerGui:WaitForChild("InventoryGui").InventoryFrame.ItemsFrame:GetChildren()
	
	inventory.ChildAdded:Connect(function(Item)
		inventoryEvent:FireClient(player, Item.Name, true)
	end)
end)

inventoryEvent.OnServerEvent:Connect(function(player, ItemName, Value, button)
	
	 if Value == false then
			local SelectedItem = player.Inventory:FindFirstChild(ItemName)
			local backpack = player.Backpack:GetChildren()
			local stuff = player.Character:GetChildren()
			
			if #backpack == 0 and not player.Character:FindFirstChildWhichIsA("Tool") then
				button.Text = "Unequip"
				button.BackgroundColor3 = Color3.new(255,0,0)
				SelectedItem:Clone().Parent = player.Backpack
			else
				for i,v in ipairs(backpack) do
					button.Text = "Equip"
					button.BackgroundColor3 = Color3.new(0,255,0)
					v:Destroy()
				end
				for i, v in ipairs(stuff) do
					if v:IsA("Tool") then
						button.Text = "Equip"
						button.BackgroundColor3 = Color3.new(0,255,0)
						v:Destroy()
					end
				end
			end
	 end
end)

–InventoryLocalScript(Baba Boi)

local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:FindFirstChild(“ItemsFrame”)

InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true then

	local ItemButton = script.Parent.ItemsFrame.ItemButton:Clone()
	ItemButton.Visible = true
	ItemButton.Name = ItemName
	ItemButton.Text = ItemName
	ItemButton.Parent = itemFrame
	
	local equipButton = script.Parent.EquipFrame["EquipButton"]
	
		ItemButton.MouseButton1Click:Connect(function()
			script.Parent.EquipFrame.Title.Text = ItemName
			script.Parent.EquipFrame.Title.Visible = true
			equipButton.Visible = true
		end)
end

end)

2 Likes

what exactly do you mean datasore function?

for loading all you need to do is when the player joins populate their inventory with the tools from the data that was just loaded

3 Likes

What I mean is I think what u said that when I get a Tool and leave the game and for example join after 1 min back the InventoryFrame should stay same

how do I do that?I’m a completely noob

Well you’d have to first setup a way to say the inventory and then you’ll be able to work from there