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!
1 Like
Do you get any errors in the console?
are you sure this isn’t printing anything
there’s nothing wrong with your script
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.
And by the way you said “activates some stuff” but all it’s scripted to do is print to the console
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)
Honestly I would prefer to do this method
local Clicker = script.Parent
Clicker.MouseClick:Connect(function()
print("Clicked")
end)
Make sure to put the script under the clickdetector!
I don’t know what to do.
There’s nothing wrong with the scripts.
(just tested the script)