I’m a tad worried with my games door system, and the possibility of memory problems arising. When players join the game, they get given an exterior and interior plot. Both those plots have doors. I add those doors into a table, and that table is used to track so I know which door a player is closest to. However, when a player leaves, I don’t delete the door from the table, as I am unsure how to track what door actually needs to be deleted. Can see in code below I have a commented out the part that would ‘fire’ when a player leaves. However, as the player has left, it means their build is destroyed (removed) and thus I can’t track where in the table their door was.
for _, v in pairs(Exteriors:GetChildren()) do
-- Plot already taken
if v.Name ~= 'Empty' then
local Build = v:FindFirstChild('Build')
if Build then
local Door = Build:FindFirstChild('Door')
if Door then
table.insert(AllDoors, Door.PrimaryPart)
-- Get hinges
local Hinge = Door.Door:FindFirstChild('Hinge')
if Hinge then
DefaultHingePositions[Hinge] = Hinge.CFrame
end
Door.PrimaryPart.Touched:Connect(function(hit)
Teleport(hit, Door)
end)
end
end
end
v:GetPropertyChangedSignal('Name'):Connect(function()
if v.Name == 'Empty' then
-- Need to find way of knowing who left, thus remove their door
else
local Build = v:FindFirstChild('Build')
if Build then
local Door = Build:FindFirstChild('Door')
if Door then
table.insert(AllDoors, Door.PrimaryPart)
-- Get hinges
local Hinge = Door.Door:FindFirstChild('Hinge')
if Hinge then
DefaultHingePositions[Hinge] = Hinge.CFrame
end
Door.PrimaryPart.Touched:Connect(function(hit)
Teleport(hit, Door)
end)
end
end
end
end)
end
In short, would this be problematic? Or can I just keep adding items into the table forever, and not have any problems? I’m not sure if this is exactly what’s causing a memory leak, but it seemed to slowly build up over the course of 20-30 minutes as people joined and left the game.