How do I make an image button remove a certain tool from a players backpack?

Hello, I am currently working on an inventory for my game but I don’t know how to make a button that when pressed removes a certain tool from the player’s backpack. I could really use some help.

You need to use a remote event to get the player and make the removal on the server too,
It’s kind of simple but I’ll make a example real quick.

1 Like

can you explain a little more?

Basically if you remove the tool on the client I don’t think the server see’s it too. So if the server tries to delete it via MouseButtion1Click you can’t get the player, so you need a LocalScript to give you the player I guess. There are better ways to do this.
Sorry I took long, but this should work.
ServerScriptService

local Event = game.ReplicatedStorage.RemoveToolFromPlayer

Event.OnServerEvent:Connect(function(player)
	player.Backpack:FindFirstChild("Codes"):Destroy()
end)

TextButton or where ever it can detect MouseButton1Click

script.Parent.MouseButton1Click:Connect(function()
	local ToolName = "Codes"
	local player = game.Players.LocalPlayer
	local Tool = player.Backpack:FindFirstChild(ToolName)
	Tool:Destroy()
	game.ReplicatedStorage.RemoveToolFromPlayer:FireServer(player)
end)
1 Like