Invisible Model, ClickDetector Not Working?

I’m currently trying to create a “Car Hood” mechanic where you can click the Model and it’ll go invisible and go visible again upon re-clicking.

When the Model goes invisible, the ClickDetector stops working, is this expected behavior? Because when you put a ClickDetector in a single part and it go invisible it’ll still work, but leaving it inside of a model makes it not work.

I’ve been through the docs of the ClickDetector but I see nothing that goes with making a model invisible stops a ClickDetector.

I don’t believe it’s my script, but this is the Script:

function Transparency(Number)
	for _, Object in pairs(Parent.CarHood:GetDescendants()) do
		if Object:IsA("BasePart") or Object:IsA("Decal") then
			Object.Transparency = Number
		end
	end
end

--// then itd be

local Open = false

Parent.CarHood.ClickDetector.MouseClick:Connect(function()
	if not Open then
		Transparency(1)
	else
		Transparency(0)
	end
	Open = not Open
end)

Format:

image

Is there something I’m doing wrong, I don’t think I could possibly find anyway to solve this neither do I have access to bug reports if this is where that belongs, sorry.

2 Likes

On the line

for _, Object in pairs(Parent.CarHood:GetDescendants()) do

I believe u forgot to add script.Parent

1 Like

ClickDetector has nothing to reference. You have it inside a model not an object.
The ClickDetector just makes the object it’s inside clickable as long as that too is set up correctly.
(CanQuery and CanTouch)

1 Like

Putting a clickdetector inside of a model makes the entire model clickable.

1 Like

This was a snippet of the code, the invisible part works, but when the model goes invisible the clickdetector doesn’t work anymore.

1 Like

Maybe add a hitbox part outside of the model, what is the hiarchy of the model?

1 Like

Have you tried a number close to invisble like 0.95?

1 Like

Any number above 0.95 will cause the clickdetector to fail.

1 Like

I don’t understand what you mean by hierarchy of the model, but if I have to, to actually do anything bout it. Unless this is a bug or something.

1 Like

Hiarchy as in part.Parent, and then the parent of that and so on. Maybe try setting up a part with clickdetector as hitbox outside the model.
But is tat model, inside of a nother model?

1 Like

I tried to recreate the issue and i couldn’t. This might just be a issue with your roblox.


The only thing different was i put the same exact script in the click detector and edited it a bit for it to work.
image

1 Like

Hmm, I didn’t know that … but I guess you can … I have always put them in objects.
Anyways, here is your fix.

local CarHood = workspace:WaitForChild("Model")

function Transparency(Number)
	for _, Object in pairs(CarHood:GetDescendants()) do
		if Object:IsA("BasePart") or Object:IsA("Decal") then
			Object.Transparency = Number
		end
	end
end

--// then itd be

local Open = false

CarHood.ClickDetector.MouseClick:Connect(function()
	if not Open then
		Transparency(1)
	else
		Transparency(0)
	end
	Open = not Open
end)

2 Likes

No idea why the way I formatted it would cause an issue, but I’ll see if the final product of it would change the outcome.

image

1 Like

Honestly i’m scratching my head on why its happening to. It SHOULD be working but it just isn’t. Though it could be something with the parent of the script or geometry of your hood.

Edit:
Heres the same exact script except a few things changed like where the hood and clickdetector should be.

function Transparency(Number)
	for _, Object in pairs(script.Parent.Parent:GetDescendants()) do
		if Object:IsA("BasePart") or Object:IsA("Decal") then
			Object.Transparency = Number
		end
	end
end

--// then itd be

local Open = false

script.Parent.MouseClick:Connect(function()
	if not Open then
		Transparency(1)
	else
		Transparency(0)
	end
	Open = not Open
end)
1 Like

This is not right … I just posted a tested working version.

1 Like

I never said it was right in any way. I just posted the script for reference, the script also does function as intended.

1 Like

Well don’t take it as rude. You said "Honestly i’m scratching my head " Just replying.

1 Like

I wasn’t being rude at all. I was just pointing out your mistake thats all.

You didn’t really give a solution, just put locals like I didn’t have any. I’m guessing the parent is a bug so I marked changing it as a solution.

omg, I meant taking what I said as rude …