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

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

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)

1 comment

0

For properties, you must have correct capitalization. So, you need to capitalize the T in transparency and the 2 C's in cancollide.

1 answer

✓ Accepted answer

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 a debouncewhich 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)

3 comments

0

What I mean, Open is the first door, and closed is the second door.

0

But, it works

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.

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