Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a tool be deleted once you click?

So I am having trouble making a barricade tool that when the model is placed (or the mouse is clicked) will place my block model. I am needing some help on adding a peice of script that will delete the tool from my backpack/inventory (im using the standard roblox backpack).

Here is my script so far:

bin = script.Parent

function onButton1Down(mouse)

	local model = bin.model:clone()

	model.Parent = game.Workspace
	model:MakeJoints()
	model:MoveTo(mouse.hit.p)

end

function onSelected(mouse)
	mouse.Icon = "rbxasset://textures\\GunCursor.png"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

if enabled then
	player.Backpack.tool:Destroy()
end

bin.Selected:connect(onSelected)


1 comment

0

HopperBins are deprecated! You should be using tools.

2 answers

✓ Accepted answer

As incapaz mentioned, HopperBins are deprecated, so you should be using tools if you aren't already. The Activated event will specifically listen for clicks while a tool is equipped.

local tool = script.Parent

function onActivated()
	--Do stuff
	tool:Destroy()
end

tool.Activated(onActivated)

2 comments

0

Wouldn't that delete the tool if the tool is equipped?

0

Nope. Activated only fires when the mouse is clicked, not when the tool is equipped.

Add this to the function at line 3:

mouse.Button1Down:Connect(function()
	player.Backpack.tool:Destroy()
end)

3 comments

0

Do the code first, then add this.

0

i did this, and for some reason it did absoutely nothing.if you want, I can share the game with you so we can work at the same time.

0

Oh forgot to mention, this is only for tools, sorry.

This discussion is preserved as it was. New answers, comments, and votes are closed.