So I had this question since yesterday and I haven't gotten a proper answer, I'm making a game were you recruit allies to help you fight. I got this tool which spawns the model by its id. But I can't find out how to remove it from the backpack once you click it.
AidanTES tried to help me but.. Didn't work..
local tool = game.StarterPack.Tool -- Replace tool with the name of your tool function(onClick) tool:Destroy() end tool.Activated:Connect(onClick)
The problem here is that you are referencing the StarterPack instead of the player's backpack.
The StarterPack is the service that contains everything cloned into the player's startergear and backpack, while the backpack just contains objects that are destroyed when the character dies.
The back / startergear objects are both located in the player objects.
With that said: here is the fixed version:
local plr = game.Players.LocalPlayer local tool = plr.Backpack.Tool -- Replace tool with the name of your tool local function onClick () tool:Destroy() end tool.Activated:Connect(onClick)
Notice that you also incorrectly declared the onClick function, the correct formatting for a function is :
function Name (arg0, arg1,...)
not
function (Name)
Hopefully this helped
I have a solution for this
local player = game:GetService("Players").LocalPlayer player.Backpack.ITEMNAMEHERE:remove()
let me know if it helps
Your fixed code will be this
local tool = game.StarterPack.Tool -- Replace tool with the name of your tool local player = game:GetService("Players").LocalPlayer function(onClick) player.Backpack.ITEMNAMEHERE:remove() end tool.Activated:Connect(onClick)