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

If, true, statements not working, why? [EDITED]

Asked by 8 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

So, I have a door which is MEANT to open when a button is clicked, but only ONE button. So, when OPEN is visible CLOSED is not, and when CLOSED is visible OPEN is not.

local LO = script.Parent.Parent.L.Open
local LC = script.Parent.Parent.L.CLOSED
local RO = script.Parent.Parent.R.OPEN
local RC = script.Parent.Parent.R.CLOSED
local L1O = script.Parent.Parent.L1.OPEN
local L1C = script.Parent.Parent.L1.CLOSED
local R1O = script.Parent.Parent.R1.OPEN
local R1C = script.Parent.Parent.R1.CLOSED
function onClicked()
    if R1C.Transparency == 1 then
            LC.Transparency = 1
            RC.Transparency = 1 
            L1C.Transparency = 1
            R1C.Transparency = 1
            LC.CanCollide = false
            RC.CanCollide = false
            L1C.CanCollide = false
            R1C.CanCollide = false
            LO.Transparency = 0
            RO.Transparency = 0 
            L1O.Transparency = 0
            R1O.Transparency = 0
            LO.CanCollide = true
            RO.CanCollide = true
            L1O.CanCollide = true
            R1O.CanCollide = true
            script.Parent.Parent.Status = "Open"
    elseif R1O.Transparency == 1 then
            LC.Transparency = 0
            RC.Transparency = 0 
            L1C.Transparency = 0
            R1C.Transparency = 0
            LC.CanCollide = true
            RC.CanCollide = true
            L1C.CanCollide = true
            R1C.CanCollide = true
            LO.Transparency = 1
            RO.Transparency = 1 
            L1O.Transparency = 1
            R1O.Transparency = 1
            LO.CanCollide = false
            RO.CanCollide = false
            L1O.CanCollide = false
            R1O.CanCollide = false
            script.Parent.Parent.Status = "Closed"
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
For properties, you must have correct capitalization. So, you need to capitalize the T in transparency and the 2 C's in cancollide. PreciseLogic 271 — 8y

1 answer

Log in to vote
1
Answered by
yoshi8080 445 Moderation Voter
8 years ago

Well I dunno if this is what you wanted but here are somethings that are wrong with your script.

  1. if open.transparency == 1 then will check if the parts Transparency is 0 which is will be 0 since there is no way to tell if the part will be changing. A way to do that is to add adebouncewhich would be named as opened.

  2. Transparency is lower cased, which is shouldn't be like that. it should be Transparency same for cancollide, it should be CanCollide

  3. It would be best to make a single button for this door from what the script says, so you only need one button named Open.

local open = script.Parent.Parent.Open
local door = script.Parent.Parent.Door
opened = false
-- script
function onClicked()
    if opened == false then -- if value listed above is false, door is open and turns it true
        door.Transparency = 1
        door.CanCollide = false
        open.BrickColor = BrickColor.new("Lime green") -- changes color if open
        opened = true -- sets it back to true to open it

    elseif opened == true then -- if value listed above is true, door is closed and turns it false
        door.Transparency = 0
        door.CanCollide = true
        open.BrickColor = BrickColor.new("Bright red") -- changes color if closed
        opened = false -- sets it back to false to close it
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
What I mean, Open is the first door, and closed is the second door. TheHospitalDev 1134 — 8y
0
But, it works TheHospitalDev 1134 — 8y
0
There is a way to do that, just look at my example and you're able to add it to the script, if you learned how it works. yoshi8080 445 — 8y
Ad

Answer this question