How to create a inventory system

Hello! So i have been making a system where you can break objects.
These are the 2 script I made:

local objectClicked = game.ReplicatedStorage:WaitForChild("ObjectClicked")

local Damage = 20

objectClicked.OnServerEvent:Connect(function(player,model)
	if not model then return end
	
	local healthAmount = model:GetAttribute("Health")
	
	if healthAmount then
		if healthAmount - Damage <= 0 then
			model:Destroy()
			else		
			model:SetAttribute("Health",healthAmount - Damage)
			model.Health.Background.Foreground.Size = UDim2.fromScale(healthAmount / 100,1)
		end
	end
	
end)
local UserInputService = game:GetService("UserInputService")
local objectClicked = game.ReplicatedStorage:WaitForChild("ObjectClicked")


UserInputService.InputBegan:Connect(function(input,GPE)
	if GPE then return end
	if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
	
	local RaycastParamsVariable = RaycastParams.new()
	RaycastParamsVariable.FilterType = Enum.RaycastFilterType.Whitelist
	RaycastParamsVariable.IgnoreWater = true
	RaycastParamsVariable.FilterDescendantsInstances =  game.Workspace.BreakableObjects:GetChildren() 
	
	local MousePosition = UserInputService:GetMouseLocation()
	
	local MouseRay = game.Workspace.Camera:ScreenPointToRay(MousePosition.X,MousePosition.Y)
	
	local Direction = MouseRay.Direction * 1000
	
	local Result = game.Workspace:Raycast(MouseRay.Origin, Direction, RaycastParamsVariable)
	
	if not Result then return end
	
	if Result.Instance   then
		local Model = Result.Instance:FindFirstAncestorOfClass("Model")
		if not Model then warn("There is no model for this object") return end
		print(Model.Name)
		objectClicked:FireServer(Model)
	end
end)

What I would like to achieve is to make it so when you destroy the objects they would go into your inventory. I am relatively new to scripting and dont know how I would do this. All help is appreciated <3

Just set the model’s parent to the player’s inventory.

how would i create a variable for the inventory?

Change this to:

objectClicked.OnServerEvent:Connect(function(player,model)
	if not model then return end
	
	local healthAmount = model:GetAttribute("Health")
	
	if healthAmount then
		if healthAmount - Damage <= 0 then
			model:Destroy()
			else		
			model:SetAttribute("Health",healthAmount - Damage)
			model.Health.Background.Foreground.Size = UDim2.fromScale(healthAmount / 100,1)
            model.Parent = player:WaitForChild("Backpack")
		end
	end
	
end)

so basically when i put the model to my backpack it shows in the backpack in explorer but not the actual inventory on the bottom of the screen

its probably because the model is not a tool.

It exists in your inventory (backpack) yes, but player wont be able to visualize with only you natively using roblox’s backpack

would there be a way to make a custom inventory system that does show it?