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

Opening/closing door has bugs, can anyone help?

Asked by 10 years ago

I have three parts to a door. One is a union, and the other two are regular parts. I put this script inside the union in hopes of making the union and the other two parts disappear when the union was clicked... but, it doesn't work. I don't know what I did wrong.

h = script.Parent.Parent.Handle
k = script.Parent.Parent.Knob
u = script.Parent

function onclicked()
    if h.Transparency == 0 and k.Transparency == 0 and u.Transparency == 0 and h.CanCollide == true and k.CanCollide == true and u.CanCollide == true then
        h.Transparency = 1
        k.Transparency = 1
        u.Transparency = 1
        h.CanCollide = false
        k.CanCollide = false
        u.CanCollide = false
    else
        h.Transparency = 0
        k.Transparency = 0
        u.Transparency = 0
        h.CanCollide = true
        k.CanCollide = true
        u.CanCollide = true
    end
end

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

If anyone could tell me what I did incorrectly, that would be awesome.

0
Just check the parts in explorer. Is every single one 0 transparency and CanCollide set to true? Discern 1007 — 10y
0
I think that was the problem. Thanks for the help. :) imperialstar 110 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

There is a much simpler way to do this:

h = script.Parent.Parent.Handle
k = script.Parent.Parent.Knob
u = script.Parent

local open = true

function onclicked()
    if open then
        h.Transparency = 1
        k.Transparency = 1
        u.Transparency = 1
        h.CanCollide = false
        k.CanCollide = false
        u.CanCollide = false
    open = true
    else
        h.Transparency = 0
        k.Transparency = 0
        u.Transparency = 0
        h.CanCollide = true
        k.CanCollide = true
        u.CanCollide = true
    open = false
    end
end

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

1
Would error. You're never setting "open" to false, therefore causing the second part of the if statement to not run. Discern 1007 — 10y
0
True that, fixed it. NutsNWaffles 135 — 10y
Ad

Answer this question