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:
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.
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)
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?
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)
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)