Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Doors that open on click?

Hi, I want to make doors. I made a script that opens the door when a sign is clicked. The clickdetector and the script is inside the sign. They both are supposed to make another model inivisble. Can you tell me the issue with this code?


function onClicked()
local children = game.Workspace.tardis1door:GetChildren()
for c = 1, #children do
if children[c].className == ""

    then children.Transparency= 1
    	children.CanCollide = false
       wait(5)
       children.Transparency= 0
       children.CanCollide = true


end
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thanks

2 answers

✓ Accepted answer
function onClicked()
	local children = game.Workspace.tardis1door:GetChildren()
	for c = 1, #children do
		if children[c].ClassName == "" then
			children[c].Transparency= 1
        		children[c].CanCollide = false
			wait(5)
       			children[c].Transparency= 0
       			children[c].CanCollide = true
		end
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

You needed the [c] after children to select the specific child. It should work now.

1 comment

1

To add to what Nifer said: You may run into the problem that 'className' is nil. If this happens, do 'ClassName' instead.

Do : (Instead of a clicked script,More efficient way of doing it is .Touched)

script.Parent.Touched:connect(function(hit)
lc = game.Workspace.tardis1door:GetChildren()
lc.Transparency = 1
wait(5)
lc.Transparency = 0
end)

Hope this helped.

3 comments

0

Oh also,If you want a .Clicked() then replace the bottom code with : " script.Parent.MouseButton1Down:connect(onClicked)"

0

Oh yeah! Thanks for pointing that out!

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.