Open door script on click

Im trying to make a door open when you click on it and since im not good enough to animate it to slide open i will just make it go invisible once you click on it and 5 seconds later it should just appear again both dissapearing and appearing with a sound, below is the script, it doesnt work…

local model = script.Parent.parent:getchildren
local clickdetector = script.Parent




local set = true


clickdetector.MouseClick:Connect(function()
	
	if (set == true) then
		
	
	model.transparency = 1
	
	wait(5)
	
		set = false
		model.transparency = 0
	end
	if (set == false) then
		model.transparency = 0

		set = true

		
		


end)



locations:
image

1 Like

local model = script.Parent.parent
local clickdetector = script.Parent

local set = true

clickdetector.MouseClick:Connect(function()

if set == true then

set = false

model.Parent = game.ReplicatedStorage

wait(5)

	set = true
	model.Parent = game.Workspace
end

end)

2 Likes

1- it’s GetChildren() and not getchildren

2- I dont think you need to use any table here, if you want to open a single door.
You could simply assign it as -
local model = script.Parent.parent

2 Likes

hi, i will look onto script later but i want to inform u, u need to change “CanCollide” To Make Players Or Objects Pass Throught It. Transparency Is Just Visibility Of Object.

2 Likes

Try this:

local model = script.Parent.Parent
local clickdetector = script.Parent

local set = true

for _,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				wait(5)
				set = false
				v.Transparency = 0
			end
			if (set == false) then
				v.Transparency = 0

				set = true
			end
		end)
	end
end

I changed a bit of your code, but didn’t replace it completely

3 Likes

its a group of parts so i thought i had to get the contents

Made it so that the models gets parented to replicated storage since theres no existing function to set a transparency for a model…

1 Like

i Checked Ur Code And Here Is Your Mistakes.

you wrote script.Parent.parent:getchildren but it must be script.Parent.Parent:GetChildren()
you don’t need a table to do that anyways.

also its “Transparency” not “transparency” and. Models Don’t Got Transparency Property its only for Parts/MeshParts Etc.

I Also Can’t See The “End” For 2. “If”

1 Like

It is :GetChildren() not GetChildren…

Oops sorry you edited I didnt notice…

how do i make this also work for wedges? because it doesnt change wedges, also is there a delay or is that just my lag?

also here is edited with cancollide added

local model = script.Parent.Parent
local clickdetector = script.Parent

local set = true

for _,v in pairs(model:GetChildren()) do
if v:IsA(“Part”) then
clickdetector.MouseClick:Connect(function()
if (set == true) then
v.Transparency = 1
v.CanCollide = false
wait(5)
set = false
v.Transparency = 0
v.CanCollide = true
end
if (set == false) then
v.Transparency = 0
v.CanCollide = true

			set = true
		end
	end)
end

end

Just copy the script from if v:IsA("Part") then and paste it in the below and change the “Part” to “WedgePart”, it can be anything, if you didn’t understand, here’s:

local model = script.Parent.Parent
local clickdetector = script.Parent

local set = true

for _,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end
	
	if v:IsA("WedgePart") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end
end
1 Like

this works as intended, thanks!
on a sidenote, how would i go about adding a sound if it closes or opens?

Find a sound from library and copy the id from the link, and add a “Audio” from Roblox Studio into your models, and paste the id into the Audio properties, and you can play it inside of open door using Audio:Play() and Audio:Stop(), I can’t explain it more detail.

1 Like