Door doesn't open/close when Bool value changes

The Bool value is changing, but when it gets changed, it should do the things stated below, but it’s not doing anything.

local value = script.Value

	value.Changed:Connect(function(newValue)
	if newValue == true then
	wait()
	script.Parent.Parent.Parent.Parent.Closed.Transparency = 1
	script.Parent.Parent.Parent.Parent.Closed.CanCollide = false
	-----
	script.Parent.Parent.Parent.Parent.Open.Transparency = 0 
	script.Parent.Parent.Parent.Parent.Open.CanCollide = true
	script.Parent.Parent.Parent.Sound:Play()

	elseif newValue == false then
	wait()
	script.Parent.Parent.Parent.Sound2:Play()
	script.Parent.Parent.Parent.Parent.Closed.Transparency = 0
	script.Parent.Parent.Parent.Parent.Closed.CanCollide = true
	-----
	script.Parent.Parent.Parent.Parent.Open.Transparency = 1
	script.Parent.Parent.Parent.Parent.Open.CanCollide = false
	script.Parent.Enabled = true
    end
end)
2 Likes

This is because you’re writing the code for closing the door, and the code for opening the door, in the same block, without a wait() in between. Try this instead

local OpenClose = script.Value -- I'd recommend using OpenClose = false instead
local Door = script.Parent.Parent.Parent.Parent.Door -- Make one door for both purposes
local Cooldown = false --A debouncer so door doesn't glitch when spam clicked

OpenClose:GetPropertyChangedSignal("Value"):Connect(function()
   if OpenClose.Value == true and Cooldown == false then
      Cooldown = true
      Door.Transparency = 1
      Door.CanCollide = false
      wait(2) --Cooldown time
      Cooldown = false
    else
      Cooldown = true
      Door.Transparency = 0
      Door.CanCollide = true
      wait(2) --Cooldown time, but for the second function
      Cooldown = false
   end
end)

PS: Are you new here in Roblox Studio? Welcome to the team bro. :grinning:

1 Like

Not really new to Roblox Studio, but new at scripting, thanks anyways.

However the problem is not about the closing and opening, because it works, but now I have to change the code that it doesn’t open and close when holding E, it should open and close when the Bool Value changes to false or true, but it does nothing.

Btw the Open and Close are parts, everytime I open or close the door, the other part is getting invisible and doesn’t collide.

1 Like

Are there any underlined errors in the studio?

1 Like

No there are no underlined errors, I’ve tried everything already.

When you’re facing a problem that you can’t figure out on scripting. Printing is a very good method for debugging. Try this script and check the console.


	value.Changed:Connect(function(newValue)
	if newValue == true then
	wait()
	script.Parent.Parent.Parent.Parent.Closed.Transparency = 1
	script.Parent.Parent.Parent.Parent.Closed.CanCollide = false
	print("DOOR HAS BEEN OPENED")
	script.Parent.Parent.Parent.Parent.Open.Transparency = 0 
	script.Parent.Parent.Parent.Parent.Open.CanCollide = true
	script.Parent.Parent.Parent.Sound:Play()

	elseif newValue == false then
	wait()
	script.Parent.Parent.Parent.Sound2:Play()
	script.Parent.Parent.Parent.Parent.Closed.Transparency = 0
	script.Parent.Parent.Parent.Parent.Closed.CanCollide = true
	print("DOOR HAS BEEN CLOSED")
	script.Parent.Parent.Parent.Parent.Open.Transparency = 1
	script.Parent.Parent.Parent.Parent.Open.CanCollide = false
	script.Parent.Enabled = true
    end
end)```

Is this supposed to be wait()?

1 Like

No the open and closed are parts, the door has 2 parts, when it openes the closed part gets invisible and cant collide, while the other one gets visible and can collide.

So the opening and closing can’t be the problem since it works, it just started not to work when I added the Bool Value.

The script has to check everytime if the value changes and if it does, it should open or close the door.

Maybe check the names if there are any that are incorrect, are there any errors in the output?

I see.

This is very innefficient in coding terms, since you need to assign or somehow refer to every part that deals with the door. Please use the least amount of parts posible to save time in coding, and have it placed in a model.

Ok so you’re dealing with a ProximityPrompt. In the script that deals with the proximity prompt and turning the bool to true or false, you’d wanna write:

local Trigger = script.Parent --Script is parented to the ProximityPrompt
local Value = --Reference to the Value

function ChangeBool()
   if Value.Value == false then
      Value.Value = true
   else
      Value.Value = false
   end
end

Trigger.PromptButtonHoldEnded:Connect(ChangeBool)

Personally I recommend using only one script for this instance, since all of it can be managed by one script. But this should be a good solution to your ailment.

1 Like