Can someone help me? I'm trying to make an open and close part and when you click it, it disappears and the opened part appears. It opens and closes but it shows the click detector when it disappears, so it destroys itself when you click it in the script, and there is another script in the opened part that puts another click detector in the closed part, but the script doesn't recognize the click detector and does nothing.
The first part script:
function onClick() if script.Parent.Parent.patrock2.Transparency == 1 then script.Parent.Parent.patrock2.Transparency = 0 script.Parent.Parent.windmill2.Transparency = 0 script.Parent.Transparency = 1 script.Parent.Parent.windmill1.Transparency = 1 script.Parent.ClickDetector:Destroy() Instance.new("ClickDetector",script.Parent.Parent.patrock2) end end script.Parent.ClickDetector.MouseClick:connect(onClick) --The second script below function onClicked() if script.Parent.Parent.patrock1.Transparency == 1 then script.Parent.Transparency = 1 script.Parent.Parent.windmill2.Transparency = 1 script.Parent.Parent.patrock1.Transparency = 0 script.Parent.Parent.windmill1.Transparency = 0 script.Parent.ClickDetector:Destroy() Instance.new("ClickDetector", script.Parent.Parent.patrock1) end end script.Parent.ClickDetector.MouseClick:Connect(onClicked)
When you instance a new ClickDetector, you never assign It to a Touched event. Try this:
function onClick() if script.Parent.Parent.patrock2.Transparency == 1 then script.Parent.Parent.patrock2.Transparency = 0 script.Parent.Parent.windmill2.Transparency = 0 script.Parent.Transparency = 1 script.Parent.Parent.windmill1.Transparency = 1 script.Parent.ClickDetector:Destroy() local cd1 = Instance.new("ClickDetector",script.Parent.Parent.patrock2) cd1.MouseClick:Connect(onClicked) end end script.Parent.ClickDetector.MouseClick:connect(onClick) --The second script below function onClicked() if script.Parent.Parent.patrock1.Transparency == 1 then script.Parent.Transparency = 1 script.Parent.Parent.windmill2.Transparency = 1 script.Parent.Parent.patrock1.Transparency = 0 script.Parent.Parent.windmill1.Transparency = 0 script.Parent.ClickDetector:Destroy() local cd2 = Instance.new("ClickDetector", script.Parent.Parent.patrock1) cd2.MouseClick:connect(onClick) end end script.Parent.ClickDetector.MouseClick:Connect(onClicked)