ClickDetector not working

  1. **What do you want to achieve? I want to make a Dumpster Lid open and close when you click on it.

  2. **What is the issue?


    The error and the Thumb are not appearing when i hover over the lid, My cursor also dissapears when i hover over the invisible lid, any help with that?

  3. **What solutions have you tried so far? For now, I cannot find anything that helped me solve this problem because i have an unknown source in the error.

Here’s also the Unknown source just in case it’s important
Explorer

This is a LocalScript in the StarterGUI

local detector1 = game.Workspace.Dumpster1.Lid.ClickDetector
local detector2 = game.Workspace.Dumpster1.OpenLid.ClickDetector

detector1.MouseClick:Connect(function()
	game.Workspace.RemoteEvent:FireServer()
end)

detector2.MouseClick:Connect(function()
	game.Workspace.RemoteEvent:FireServer()
end)

And this is the RemoteEvent Script

local Lid = game.Workspace.Dumpster1.Lid
local OpenLid = game.Workspace.Dumpster1.OpenLid

game.Workspace.RemoteEvent.OnServerEvent:Connect(function()
	if Lid.Transparency == 0 then
		Lid.Transparency = 1
		Lid.CanCollide = false 
		OpenLid.CanCollide = true
		OpenLid.Transparency = 0
		if Lid.Transparency == 1 then
			Lid.Transparency = 0
		    Lid.CanCollide = true
		    OpenLid.CanCollide = false
		    OpenLid.Transparency = 1
		end
	end
end)

If there are some Experienced Scripters that are reading this, Is there any better way i can detect if the lid is open or closed or is this okay?
I tried to put as much Details as i could, hopefully it helps. Thanks.

Are you sure that the detector1 ClickDetector exists, and that you are referencing it correctly? The error says that it cannot find the ClickDetector inside of Dumster1.Lid.

If you try using WaitForChild, does it fix the error?

local detector1 = game.Workspace.Dumpster1.Lid:WaitForChild("ClickDetector")
local detector2 = game.Workspace.Dumpster1.OpenLid:WaitForChild("ClickDetector")

I’m confused as to why you are using StarterGui, you can have the ClickDetector in a part in workspace without having to firing events. If you are attempting to open the bin from a GUI you need to use TextButtons.

It does “fix” it at some level. Now when i hover my mouse over any of the lids my cursor just dissapears instead of turning into a hand, is my roblox studio bugged, and when i click, nothing happens

Because i did it the way Alvin did in this video. I’m still a Begginer at scripting, so idk how much of the stuff works.

Hmm. I don’t see no clickdetector in your “lid”.

I put it in, i forgot to do it, but it still doesn’t work, my cursor just dissapears when i hover over any of the lids. and when i click, nothing happens

Put this script into a part you want to use to open/close the lid.

local ClickDetector = script.Parent
local Lid = game.Workspace.Dumpster1.Lid
local OpenLid = game.Workspace.Dumpster1.OpenLid
local enabled = false


function Clicked()
     if enabled == false then -- if the lid is closed then do code
        enabled = true
       Lid.Transparency = 1
       Lid.CanCollide = false
       OpenLid.CanCollide = true
       OpenLid.Transparency = 0
elseif enabled == true then -- if the lid is open then do code
       enabled = false 
       Lid.Transparency = 0
       Lid.CanCollide = true
       OpenLid.CanCollide = false
       OpenLid.Transparency = 1
		 
end
end
ClickDetector.MouseClick:Connect(Clicked)

Let me know if anything doesn’t work.

If clickdetector exists as a child of the union then it shouldn’t give you that error. Additionally its good practice to put in print statements for debugging,

1 Like

Explorer

Just a sec

Can you show me where you have the ClickDetector in Explorer please?

Good news,

  1. I referenced the clickdetector in the explorer as it should’ve been, but, the lid only opens and won’t close. There is no error
  2. The ClickDetector Cursor appears when i hover over the invisible and can’t collide Lids, how can i fix that?

The ClickDetector will always appear even if it’s Parent Part is invisible, you could add a lever to the side of the bin and put the ClickDetector in there.

https://gyazo.com/bc438c90562ff3b8af37e3749e622f7d

The script works fine on my end, so i recommend making the lever part and storing the clickDetector in that.

1 Like

Well, I just now realised that the 2nd clickdetector is useless. It only opens and closes on the clickdetector on the “Lid”. So thank you, you really helped me

1 Like