Hello! Script to make some things to be not colliding, or colliding depending ona button

Hello, it is in a script and it is not seem to be working, is fyou can help i would appreciate it. Thank you

if script.Parent.Text == "Open Gate" then
	script.Parent.Text = "Close Gate"
	game.Workspace.JudgeCont.Roundwalls.Wall1.CanCollide = false
	game.Workspace.JudgeCont.Roundwalls.Wall2.CanCollide = false
	game.Workspace.JudgeCont.Roundwalls.Wall3.ChildAdded = false
	game.Workspace.JudgeCont.Roundwalls.Open.Transparency = 0
	game.Workspace.JudgeCont.Roundwalls.Open.CanCollide = true
	game.Workspace.JudgeCont.Roundwalls.Closed.Transparency = 1
else
	script.Parent.Text = "Open Gate"
	game.Workspace.JudgeCont.Roundwalls.Wall1.CanCollide = true
	game.Workspace.JudgeCont.Roundwalls.Wall2.CanCollide = true
	game.Workspace.JudgeCont.Roundwalls.Wall3.ChildAdded = true
	game.Workspace.JudgeCont.Roundwalls.Open.Transparency = 1
	game.Workspace.JudgeCont.Roundwalls.Open.CanCollide = false
	game.Workspace.JudgeCont.Roundwalls.Closed.Transparency = 0
end```

Please do not ask people to write entire scripts or design entire systems for you. If you can't answer the three questions above, you should probably pick a different category.
  1. So, you want a gate that opens and closes when you Chat “Open Gate” or “Close gate”?
  2. You need to post the entire script.
  3. Fix the lines with Wall3.ChildAdded = false and Wall3.ChildAdded = true to Wall3.CanCollide = false and Wall3.CanCollide = true
  4. You also need to post a picture of the Explorer window with the gate Parts (and children of those Parts) visible so we can see how your gate and script work together.
  5. And then tell us what errors you get in the Output window in Studio when you test your game.

Next, you could put a variable before the beginning of the script like:
roundwalls = game.Workspace.JudgeCont.Roundwalls
making sure the uppercase and lowercase letters are the same, then in the later sections just have

if script.Parent.Text == "Open Gate" then
	script.Parent.Text = "Close Gate"
	roundwalls.Wall1.CanCollide = false
    roundwalls.Wall2.CanCollide = false
2 Likes

if you want to make it a physical button you are going to have to make a part (AKA the button) then add a click detector in it and add the following code into a script inside the button

local clickDetector = script.Parent.ClickDetector
local Roundwalls = game.Workspace.JudgeCont.Roundwalls

local function buttonClicked()
   if Roundwalls.Wall1.CanCollide == true then

    Roundwalls.Wall1.CanCollide = false
	Roundwalls.Wall2.CanCollide = false
	Roundwalls.Wall3.ChildAdded = false
	Roundwalls.Open.Transparency = 0
	Roundwalls.Open.CanCollide = true
	Roundwalls.Closed.Transparency = 1
   else
    Roundwalls.Wall1.CanCollide = true
	Roundwalls.Wall2.CanCollide = true
	Roundwalls.Wall3.ChildAdded = true
	Roundwalls.Open.Transparency = 1
	Roundwalls.Open.CanCollide = false
	Roundwalls.Closed.Transparency = 0
   end
end)

clickDetector.MouseClick:Connect(buttonClicked)

Hope this helped, if there are any errors with this code please let me know :slight_smile:

2 Likes