Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Doors that open on click?

Asked by
DevNetx 250 Moderation Voter
10 years ago

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?

01function onClicked()
02local children = game.Workspace.tardis1door:GetChildren()
03for c = 1, #children do
04if children[c].className == ""
05 
06    then children.Transparency= 1
07        children.CanCollide = false
08       wait(5)
09       children.Transparency= 0
10       children.CanCollide = true
11 
12 
13end
14end
15end
16 
17script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thanks

2 answers

Log in to vote
3
Answered by
Nifer2 174
10 years ago
01function onClicked()
02    local children = game.Workspace.tardis1door:GetChildren()
03    for c = 1, #children do
04        if children[c].ClassName == "" then
05            children[c].Transparency= 1
06                children[c].CanCollide = false
07            wait(5)
08                children[c].Transparency= 0
09                children[c].CanCollide = true
10        end
11    end
12end
13 
14script.Parent.ClickDetector.MouseClick:connect(onClicked)

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

1
To add to what Nifer said: You may run into the problem that 'className' is nil. If this happens, do 'ClassName' instead. Perci1 4988 — 10y
Ad
Log in to vote
0
Answered by
iLegitus 130
10 years ago

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

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

Hope this helped.

0
Oh also,If you want a .Clicked() then replace the bottom code with : " script.Parent.MouseButton1Down:connect(onClicked)" iLegitus 130 — 10y
0
Oh yeah! Thanks for pointing that out! Nifer2 174 — 10y
0
No problem. iLegitus 130 — 10y

Answer this question