Hello, can someone tell me how to make a part that when it has been clicked with an particular item equipped it will run an event,
Thanks
Ok so this isnt hard but you could make a script in each teach doing this
local part = game.Workspace.PARTNAME local handle = script.Parent.Handle part.Touched:Connect(function(hit) if handle hit then --RUN FUNCTION HERE end)
Hey there! Making this is pretty simple. I'll show you how!
Make sure to have a ClickDetector inserted in your part. This will help detect when the part has been clicked.
Code:
local Part = game.Workspace.PartName --reference variable for the part, make sure to change PartName to your part's name local ClickDetector = Part.ClickDetector --reference variable for the clickdetector inside of your part local Tool = script.Parent --reference variable for the tool Tool.Equipped:Connect(function() --event for whenever the tool is equipped, meaning that the code in this function will only run when the tool is equipped ClickDetector.MouseClick:Connect(function() --event for when the part is clicked, and it will only run when the tool is equipped, since of that other event --Function here end) end)
That should work, and hopefully you understood that. Have a great day.
I think i have an answer for your question, so basically you are trying to click the part only if you have an specific tool equipped right? It's not that hard, just disable the script, as you can see in the script properties you will see a "Disabled" property, click that to disable the script so it wont work. And now you need to enable it when the tool is equipped so now scripts locations. Make a script inside the tool and a script inside the clickdetector of the part you want to click. And now to be able to click it only when the tool is equipped go to the script of the tool and do this:
local isEquipped = false local tool = script.Parent local script = workspace.Part.ClickDetector.Script -- Change it if it's wrong. tool.Equipped:Connect(function() if not isEquipped then isEquipped = true script.Disabled = false end end) tool.Unequipped:Connect(function() if not isEquipped then isEquipped = false script.Disabled = true end end)
That would be the code you must do to enable the script when the specific tool is equipped. I really hope this answer helps you and good luck with it! If you have any errors in the output fix them and if something isn't working, remember to use Print() after the functions to see if the functions are functioning haha! Also what happened to the script within the ClickDetector? Idk you need to put your own code there haha. Make sure you Disable the script of the ClickDetector and not the tool's script one! Also big sorry to don't use codeblock, i'm not pretty good using codeblocks here, but the important is that you can see how to do it. Byee :)