Character Memory Leak

while char.Parent == nil do
	char.AncestryChanged:Wait()
end

Would this cause an infinite loop/data leak if let’s say the character was destroyed before the AncestryChanged or the AncestryChanged never fires?

I mean why would you need that and the character would be nil making it error because there is no character to have a parent

local loop = nil

local state = script.Parent.BoolValue
local loop = nil
loop = game:GetService("RunService").Heartbeat:Connect(function()
  if not char.Parent then
    loop:Disconnect()
    state.Value = true
  end
end)
state.Changed:Connect(function()
  if state.Value then
    char.AncestryChanged:Wait()
    state.Value = false
    loop = game:GetService("RunService").Heartbeat:Connect(function()
  if not char.Parent then
    loop:Disconnect()
    state.Value = true
  end
end)
  end
end)
1 Like