I have several NPCs, when I destroy the first one it causes a lag spike, but the rest are fine. If I remove the humanoid and just have an empty rig, it doesn’t cause that weird lag spike. But for my animations to work, I require the humanoid. Is there any work around this?
SellPart.ProximityPrompt.Triggered:Connect(function(player)
local char = game.Workspace:FindFirstChild(player.Name)
if not char then return end
local HumanoidRootPart = char:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end
local WeldNPC = HumanoidRootPart:FindFirstChild("WeldNPC")
if not WeldNPC then return end
for _, v in pairs(game.Workspace.Noobs:GetChildren()) do
local StatsFolder = v:FindFirstChild("Stats")
if StatsFolder then
local BeingCarried = StatsFolder:FindFirstChild("BeingCarried")
local WhoIsCarrying = StatsFolder:FindFirstChild("WhoIsCarrying")
if WhoIsCarrying and BeingCarried and WhoIsCarrying.Value == player.Name and BeingCarried.Value == true then
v:Destroy()
WeldNPC:Destroy()
break -- Stop loop after finding the NPC
end
end
end
end)