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
9 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?


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

Log in to vote
3
Answered by
Nifer2 174
9 years ago
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
To add to what Nifer said: You may run into the problem that 'className' is nil. If this happens, do 'ClassName' instead. Perci1 4988 — 9y
Ad
Log in to vote
0
Answered by
iLegitus 130
9 years ago

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.

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

Answer this question