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

How to make part that will be removed when clicked on it while holding a tool?

Asked by
Ligij 5
3 years ago

Im just trying to make broom system that will work when you click on part when holding a tool the part will be removed?

3 answers

Log in to vote
0
Answered by 3 years ago

You can use tool.Equipped, and that will give you the player's mouse, since click detectors do not work when you hold the tool, you should use the mouse.Button1Down and mouse.Target to find out which object the player is aiming at (when clicked). Then you can fire a remote event to the server in order to destroy the part (since the whole mouse part is in the local script, the mouse is nil in a server script).

So, to sum up, you can learn using these resources:

tool.Equipped

mouse.Button1Down

mouse.Target

Remote Events

Ad
Log in to vote
-1
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Add a clickDetector to the part and add a script in it and write this in the script

script.Parent.MouseClick:Connect(function(clicker)
    local Character = clicker.Character

    if Character:FindFirstChild("toolNameHere") then
        script.Parent.Parent:Destroy()
    end
end)
0
Please don't give code, scripting helpers is not a request website, so you should not give code to them Leamir 3138 — 3y
0
Dude the whole point of this website is to ask for help and how to do things, Leamir cookie_more 30 — 3y
0
You can make it like @LightningLIon58, this is NOT a request website, if we just give code, we are encouraging people to ask for code Leamir 3138 — 3y
Log in to vote
-1
Answered by 3 years ago

Use this local script in the tool:

local Part = -- Reference the part in this variable

script.Parent.Equipped:Connect(function()
   local ClickDetector = Instance.new("ClickDetector)
    ClickDetector.Parent = Part
end)

script.Parent.Unequipped:Connect(function()
    Part.ClickDetector:Destroy()
end)

Put this normal script in the part you want to get destroyed:

local Part = -- Reference the part in this variable

if Part.ClickDetector then
    Part.ClickDetector.MouseClick:Connect(function()
        Part:Destroy()
    end)
end

These scripts makes it so when it gets clicked (only if there is a click detector, which gets put into the part if the tool is equipped) it gets destroyed, and it won't work when it is unequipped, because it gets destroyed.

Answer this question