Gate script not working

Hi, I’m making a gate and here is the script:
function leftclick()
script.Parent.Parent.CanCollide = false
script.Parent.Parent.Transparency = 1
end

script.Parent.MouseButton1Click:Connect(leftClick)
This is one of my first scripts, so if it makes no sense, please bear with me!

Try changing this one to a lowercase “c”

script.Parent.Parent.CanCollide = false
script.Parent.Parent.Transparency = 1
end

script.Parent.MouseButton1Click:Connect(leftClick)

Alright, it didn’t fully fix it, but it did remove an error, so that is good.

No. The parent is a part, and the parent’s parent is the full model.

Alright.
I’m testing it right now.

Alright, it’s now giving me the click hand thing, but nothing happens when I click it.

No luck.
There was also an error, but I fixed that.
The script now looks like this:

function leftclick()
	script.Parent.MouseButton1Click:Connect(leftclick)
		script.Parent.Parent.Parent.CanCollide = false
        script.Parent.Parent.Parent.Transparency = 1
end

script.Parent.MouseClick:Connect(leftclick)

No luck still.
The script still doesn’t do anything.
However, output says “CanCollide is not a valid member of Model"Workspace.gate”

Try script.Parent.MouseButton1Down:connect(leftclick)

Where do I put that in the script?

Where stay script.Parent.MouseClick:Connect(leftclick) there must be stay script.Parent.MouseButton1Down:connect(leftclick) Im not sure.

You see the keyword there? “Model” To make all parts transparent with collisions off - Just loop through the model.

(Also define the Gate as it’s own variable, pleasee!!!)

for _,v in pairs(Gate:GetChildren()) do
      if v.ClassName == "Part" or v.ClassName == "MeshPart" then
           -- Other code here, but instead of script.Parent.Parent.Parent do "v.CanCollide"
      end
end

Please also read up on this, it will help you a bunch!

Alright, quick question.
Do they have to be named Part1, Part2, and so on, or does it just know what that means?

Could you send a screenshot of the model collapsed in the explorer?

Alrighty. Thanks a lot, I will try it.

Yah, I’m trying B, unless something weird happens.

Based of the screenshot here’s a messy example of what the script could be:

local Gate = script.Parent.Parent.Parent -- Defines the gate (very messy lol)

script.Parent.MouseClick:Connect(function()
	for _,v in pairs(Gate:GetChildren()) do -- Loops through the gates  children
		if v.ClassName == "Part" or v.ClassName == "MeshPart" then -- If the child is a part or a meshpart
			v.Transparency = 1 -- Make the child invisible and turn the cancollide off
			v.CanCollide = false
		end
	end
end)

(I copied S1RKKnightys code)

It worked! Thanks a lot, super helpful!

1 Like