I am making a door system which contains 2 models, A and B. A being representative of the Closed model, and B representing the Open model.

What happens, however, is that it will function correctly for approximately 5-10 minutes, and then suddenly the ClickDetectors inside of the models disappear, and all parts inside of the system become transparent, although still there. There are no other scripts in the entire place, and the parts are anchored and have collisions enabled. There are also no errors generated.

Before After

My code:

--//STORE TRANSPARENCY AND COLLISIONS FOR 'A'
local partTransparencyA = {}
local collisionsA = {}
for _,object in pairs(script.Parent.A:GetChildren()) do
	table.insert(partTransparencyA,object.Transparency)
	table.insert(collisionsA,object.CanCollide)
	wait()
end

--//STORE TRANSPARENCY AND COLLISIONS FOR 'B'
local partTransparencyB = {}
local collisionsB = {}
for _,object in pairs(script.Parent.B:GetChildren()) do
	table.insert(partTransparencyB,object.Transparency)
	table.insert(collisionsB,object.CanCollide)
	wait()
end

--//HIDE 'B'
for i,objb in pairs(script.Parent.B:GetChildren()) do
	objb.Transparency = 1
	objb.CanCollide = false
end	

--//CHANGE STATE
local function changeState(var)
	if var then --//Close A, Open B
		for _,obj in pairs(script.Parent.A:GetChildren()) do
			obj.Transparency = 1
			obj.CanCollide = false
			if obj.Name == "ClkA" then
				obj.ClickDetector.MaxActivationDistance = 0
			end
		end
		for i,objb in pairs(script.Parent.B:GetChildren()) do
			objb.Transparency = partTransparencyB[i]
			objb.CanCollide = collisionsB[i]
			if objb.Name == "ClkB" then
				objb.ClickDetector.MaxActivationDistance = 32
			end
		end
	else
		for _,obj in pairs(script.Parent.B:GetChildren()) do
			obj.Transparency = 1
			obj.CanCollide = false
			if obj.Name == "ClkB" then
				obj.ClickDetector.MaxActivationDistance = 0
			end
		end
		for i,objb in pairs(script.Parent.A:GetChildren()) do
			objb.Transparency = partTransparencyA[i]
			objb.CanCollide = collisionsA[i]
			if objb.Name == "ClkA" then
				objb.ClickDetector.MaxActivationDistance = 32
			end
		end	
	end
end

script.Parent.A.ClkA.ClickDetector.MouseClick:connect(function()
	changeState(true)
end)
script.Parent.B.ClkB.ClickDetector.MouseClick:connect(function()
	changeState(false)
end)

I'm not sure whether this is due to the script, or something else.

2 comments

0

Does this only happen only after you click it after the 5-10 minutes, or will it happen when you aren't event interacting with it? If it does it without you doing anything, it would be resulting from another source.

0

It will work fine up until then, and then when you click it, it happens