"Connect is not a valid member of ClickDetector"

Hey gamers, I’m trying to create a button that opens two sliding doors when clicked using the tween service. The door itself works fine, however problems have arisen when attempting to activate it through a ClickDetector. I get this error “Connect is not a valid member of ClickDetector” on line 14, and I have zero clue why. I searched online for an answer as well as the developer forums, but in places where I’ve seen it mentioned, it’s either ignored or dismissed. I have no clue what’s causing the problem, or where I would start to attempt to solve it.

Here’s the script that I’m using.
I’m making this in a place separate from anything else, and the error mentioned before is the only error I get.

local TweenService = game:GetService("TweenService")
local Lroot = script.Parent.Parent.LRoot
local Rroot = script.Parent.Parent.RRoot
local PanelSlideInfo = TweenInfo.new()

local PanelSlideTween1 = TweenService:Create(Lroot, PanelSlideInfo, {
	CFrame = Lroot.CFrame * CFrame.new(Lroot.Size.X + 0.1, 0, 0)
})

local PanelSlideTween2 = TweenService:Create(Rroot, PanelSlideInfo, {
	CFrame = Rroot.CFrame * CFrame.new(Rroot.Size.X + 0.1, 0, 0)
})

script.Parent.MouseClick:Connect(function(player)
	PanelSlideTween1:Play()
	PanelSlideTween2:Play()	
end)

Is there another ClickDetector named MouseClick potentionally?

Nope
image

This should solve your issue:

script.Parent.MouseClick.MouseClick:Connect(function(player)
	PanelSlideTween1:Play()
	PanelSlideTween2:Play()	
end)

Though, it would be easier to just rename the ClickDetector to something else to prevent confusion

1 Like

Worked, thanks!! If you don’t mind me asking though, why does this work?

The ClickDetector is named MouseClick, when you were calling Connect on it, you were basically doing:

ClickDetector:Connect(function(...)

Instead of:

ClickDetector.MouseClick:Connect(function(...)

MouseClick is a property of ClickDector, which is what you meant to access.


The reason why I suggested renaming the click detector is because it looks like you’re accessing the property, but it’s just the Instance name.

Here’s what renaming to something like it’s basic ClassName would look like:

script.Parent.ClickDetector.MouseClick:Connect(function(...)

It’s clear and there’s less confusion on whether you’re accessing an Instance or its property

1 Like

omg lol, i honestly had no clue that MouseClick was a property of ClickDetector, thank you again :3

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.