Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click to remove tool from backpack?

Asked by
Rdumb1 4
5 years ago

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)

2 answers

Log in to vote
0
Answered by 5 years ago

The problem here is that you are referencing the StarterPack instead of the player's backpack.


the difference between the backpack and StarterPack


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

0
Thank you! I noticed that it removes the tool before it spawns the npc but I put wait(1) after local function onClick () Rdumb1 4 — 5y
Ad
Log in to vote
0
Answered by
xudet 0
5 years ago
Edited 5 years ago

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)
0
Oh you also need to reference your function like > function clicked (onClick) xudet 0 — 5y
0
Will this be in the tool and will it be a normal or local script? Rdumb1 4 — 5y

Answer this question