Open and Close card Door

I think I created correct topic :cactus:

Hello! I created a door that opens when pressed (only opens if you have a card in your inventory). However, when pressed, the door is removed.

Is it possible to “change” the script so that the door disappears / opens after pressing, and appears again when pressed again?

I have a video showing a door system and a door script.

Thanks!


https://gyazo.com/f37d8f03784831c13a04f9bb26ea45bb

active = true

function onTouched(hit)
	if active == true then
	if hit.Parent.Name == script.Parent.ToolRequired.Value then
		active = false
			script.Parent.Unlock:Play()
			script.Parent.Parent.Display.BrickColor = BrickColor.new("Really black")
			script.Parent.Parent.BlockedDoor:Destroy()
	end
end
end
script.Parent.Touched:connect(onTouched)

function onClicked(player)
	if active == true then
	if player.Backpack:FindFirstChild(script.Parent.ToolRequired.Value) then
		active = false
			script.Parent.Unlock:Play()
						script.Parent.Parent.Display.BrickColor = BrickColor.new("Dark green")
			script.Parent.Parent.BlockedDoor:Destroy()
	end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Not need but image from explorer

https://gyazo.com/c32d1155149dcf97de6cd381fa165fd6

Thanks!

Why not just add another conditional statement that checks if active is false? You’ll have to change up your script a bit if you want it to properly work

local BlockedDoor = script.Parent.Parent.BlockedDoor

function onTouched(hit)
    if active == true then
	    if hit.Parent.Name == script.Parent.ToolRequired.Value then
		    active = false
			script.Parent.Unlock:Play()
			script.Parent.Parent.Display.BrickColor = BrickColor.new("Really black")
			BlockedDoor = nil
	    end
    end
end
script.Parent.Touched:connect(onTouched)

function onClicked(player)
	if active == true then
	    if player.Backpack:FindFirstChild(script.Parent.ToolRequired.Value) then
		    active = false
			script.Parent.Unlock:Play()
			script.Parent.Parent.Display.BrickColor = BrickColor.new("Dark green")
			BlockedDoor = nil
	    end

    elseif active == false then
        active = true
	    BlockedDoor.Parent = script.Parent.Parent
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

I didn’t quite understand … I changed the script, but the door stopped opening altogether… :frowning:

The thing is that, you’re attempting to call Destroy() which would permamently remove that BlockedDoor Part/Model/Whatever it is & you’re wanting to obtain it back correct?

You could either do 2 options:

  • A: Set the BlockedDoor variable to nil so that you can reference it back again if you want to close it

  • B: Change the BlockedDoor properties to have CanCollide = true, and the Transparency = 0 if you want to close it

About variable to nil I got it, at script it is have
And properties true CanCollide…
But still not work… And not open sorry