I’m making a game with over 400+ NPCs, and sometimes they get teleported to a black void at Y position -340282346638528859811704183484516925440
This is how it looks like after I zoomed into one of the NPCs, It’s just a black void:
Im pretty sure It’s happening from this part of the script:
local destination = closestPart.Position + Vector3.new(math.random(-closestPart.Size.X,closestPart.Size.X)/2,closestPart.Size.Y/2+(3.5*npc.Humanoid.BodyHeightScale.Value),math.random(-closestPart.Size.Z,closestPart.Size.Z)/2)
local speed = 0.025/(destination - npc.PrimaryPart.Position).Magnitude
local cframe = CFrame.new(npc.PrimaryPart.Position,Vector3.new(destination.X,npc.PrimaryPart.Position.Y,destination.Z))+(destination - npc.PrimaryPart.Position)
local new = Instance.new("StringValue")
new.Name = "Moving"
new.Parent = npc
spawn(function()
for i = 0,1,speed do
if npc.PrimaryPart then
npc:SetPrimaryPartCFrame(npc.PrimaryPart.CFrame:Lerp(cframe,i))
end
task.wait(0.01)
end
if npc:FindFirstChild("Moving") then
npc.Moving:Destroy()
end
end)
Also, I can’t use :MoveTo() because theres 400+ NPCs and It would create a lot of lag, I used Tween but the same problem happened
I can show the whole script but It wont help much