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