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

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

Asked by 6 years ago

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)


0
HopperBins are deprecated! You should be using tools. User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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)
0
Wouldn't that delete the tool if the tool is equipped? User#22219 20 — 6y
0
Nope. Activated only fires when the mouse is clicked, not when the tool is equipped. Perthrosama 24 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Add this to the function at line 3:

mouse.Button1Down:Connect(function()
    player.Backpack.tool:Destroy()
end)
0
Do the code first, then add this. User#22219 20 — 6y
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. dizzycutepuppy56 -4 — 6y
0
Oh forgot to mention, this is only for tools, sorry. User#22219 20 — 6y

Answer this question