local clickDetector = workspace.Part.ClickDetector
function onMouseClick()
Part.Transparency = 1
end
clickDetector.MouseClick:connect(onMouseClick)
The script and the ClickDetector is not working on the part. Does anyone know how to fix it?
local clickDetector = workspace.Part.ClickDetector
function onMouseClick()
Part.Transparency = 1
end
clickDetector.MouseClick:connect(onMouseClick)
The script and the ClickDetector is not working on the part. Does anyone know how to fix it?
There is no reference to Part
which means it’s equal to nil
and therefore will throw an error(attempt to index nil). The part reference changes based on location(I assume you wanted to write workspace.Part
?) .
--Script inside Part
--script is always equal to the script path
--.Parent is equal to the parent of the object defined(so the parent of the script)
local Part = script.Parent
--:WaitForChild() waits for an object to be added for a few seconds, named "ClickDetector"
local clickDetector = Part:WaitForChild("ClickDetector")
function onMouseClick()
Part.Transparency = 1
end
clickDetector.MouseClick:connect(onMouseClick)