it wont destroy the item in the backpack
local sword = game.Lighting.Sword local gun = game.Lighting.Gun local anotah = game.Lighting.anotahone local GButton = script.Parent.GButton local AButton = script.Parent.AButton local SButton = script.Parent.SButton local WName = script.Parent.WName local player = game.Players.LocalPlayer GButton.MouseButton1Click:connect(function() WName.Text = gun.Name gun.Parent = player.Backpack local clone = sword.Parent player:FindFirstChild("Sword"):Destroy() player:FindFirstChild("anotahone"):Destroy() end) AButton.MouseButton1Click:connect(function() WName.Text = anotah.Name anotah.Parent = player.Backpack local clone = anotah.Parent player:FindFirstChild("Sword"):Destroy() player:FindFirstChild("Gun"):Destroy() end) SButton.MouseButton1Click:connect(function() WName.Text = sword.Name sword.Parent = player.Backpack local clone = gun.Parent player:FindFirstChild("Gun"):Destroy() player:FindFirstChild("anotahone"):Destroy() end)
I recommend for this that you make a single function, since you have a lot of repeated code. To properly remove items from a player, the code needed is larger than one line (with formatting), so it would become even worse if you had to repeat it.
local function RemoveItems(Player,...) -->> ... is a useful thing that can be more than one value (it is a tuple) -->> You can call the function with as many values as you like after the player and they will all be in ... local ItemsToRemove = {...} -->> Put the added values into a table local Backpack = Player:WaitForChild("Backpack") local Character = Player.Character for _,ItemName in pairs (ItemsToRemove) do -->> Loop through the items to remove local Item = Backpack:FindFirstChild(ItemName) if Item then -->> The below line will error if it isn't found, so we have this if statement Item:Destroy() end end if Character then for _,ItemName in pairs (ItemsToRemove) do local Item = Character:FindFirstChild(ItemName) -->> Search the player also, because the item may be equipped if Item then Item:Destroy() end end end end -->> Example of it in action Button.MouseButton1Click:Connect(function() RemoveItems(Player,"Sword","Gun","Tree","blahblah") -->> One line to remove 4 items! end)
Hope I helped!
~TDP