Hey there! I am having trouble with my small system, I would like to get some help & feedback for solve this out.
Here is my script from a system that when clicking on a part (with a clickdetector, so a button) it activates some stuff, here’s my code & screenshot of the model organization:
local part = script.Parent
local clickDetector = part:WaitForChild("ClickDetector")
local function onClick()
print("Part clicked! Do something here.")
end
-- Connect the onClick function to the ClickDetector's MouseClick event
clickDetector.MouseClick:Connect(onClick)
The problem is that when I click on the part, nothing happens… I would really appreciate any help, thanks!
I tried this in studio, and it works for me. Make sure you’re close enough to the part, and try increasing MaxActivationDistance inside the ClickDetector’s properties.
You need to put the script inside the ClickDetector for it to work.
Then, your code would have to look something like this:
local clickDetector = script.Parent
local part = clickDetector.Parent
local function onClick()
print("Part clicked! Do something here.")
end
-- Connect the onClick function to the ClickDetector's MouseClick event
clickDetector.MouseClick:Connect(onClick)