Hello! I am currently at a state where I am unknown on where to fix this bug. This is a script that clones workspace and puts in into viewport. However when a new part is added to a player model. The game starts having one lag spike per object. And I don’t know why. Any help would be appreciated!
Code:
Model.DescendantAdded:Connect(function(Child)
if Child:IsA("Part") or Child:IsA("MeshPart") or Child:IsA("BasePart") then
local RenderPart = Child:Clone()
Child.Archivable = false
RenderPart.Parent = ViewPort
PartUpdater = RunService.Heartbeat:Connect(function()
if RenderPart.CFrame ~= Child.CFrame then
RenderPart.CFrame = Child.CFrame
end
if RenderPart.Transparency ~= Child.Transparency then
RenderPart.Transparency = Child.Transparency
end
if RenderPart.Color ~= Child.Color then
RenderPart.Color = Child.Color
end
if RenderPart.Size ~= Child.Size then
RenderPart.Size = Child.Size
end
if RenderPart.Material ~= Child.Material then
RenderPart.Material = Child.Material
end
end)
Model.DescendantRemoving:Connect(function(child)
if child == Child then
Child.Archivable = true
RenderPart:Destroy()
PartUpdater:Disconnect()
end
end)
end
end)