I am currently making a Pet System with Rigs that contains a Humanoid, the Pets are getting moved with MoveTo(). If i add a Pet to the Pet Folder over the Client everything is fine. But if i add one over the Server the pet takes ages to Load? not like 1 sec more like 50 Seconds. i tried to remove every asset and use a fresh new generatet Rig still the same problem. Tryed to use Attachment and AlignPosition istead of MoveTo(). Same thing it takes ages to load.
Video:
Video Streamable
my Current Move Script
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local FOLLOW_DISTANCE = 6
local WALK_SPEED = 16
local RADIUS = 5
local RADIUS_STEP = 3
local ARC_DEGREES = 90
local UPDATE_INTERVAL = 0.05
local WORKERS_PER_RING = 4
local MAX_DISTANCE = 50
local WORKER_FOLDER_NAME = "PlayerWorkers"
local humanoidRootPart
local workerFolder = workspace:WaitForChild(WORKER_FOLDER_NAME)
local playerWorkerFolder = workerFolder:WaitForChild(player.Name)
local activeWorkers = {}
local lastUpdate = 0
local function positionWorkerBehindPlayer(worker)
local rootPart = worker:WaitForChild("HumanoidRootPart")
if humanoidRootPart and rootPart then
local behindPlayer = humanoidRootPart.CFrame.Position - humanoidRootPart.CFrame.LookVector * FOLLOW_DISTANCE
rootPart.CFrame = CFrame.new(behindPlayer, humanoidRootPart.Position)
end
end
local function refreshActiveWorkers()
activeWorkers = {}
for _, worker in ipairs(playerWorkerFolder:GetChildren()) do
local humanoid = worker:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.WalkSpeed = WALK_SPEED
table.insert(activeWorkers, worker)
positionWorkerBehindPlayer(worker)
end
end
end
local function getWorkerRingPositions(count)
local positions = {}
local totalRings = math.ceil(count / WORKERS_PER_RING)
for ring = 1, totalRings do
local ringRadius = RADIUS + (ring - 1) * RADIUS_STEP
local workersInRing = math.min(WORKERS_PER_RING, count - #positions)
local angleStep = math.rad(ARC_DEGREES / math.max(workersInRing - 1, 1))
local baseAngle = math.rad(-ARC_DEGREES / 2)
for i = 0, workersInRing - 1 do
local angle = baseAngle + (i * angleStep)
local x = math.sin(angle) * ringRadius
local z = math.cos(angle) * ringRadius - FOLLOW_DISTANCE
table.insert(positions, Vector3.new(x, 0, z))
end
end
return positions
end
local function getOreRingPositions(count, radius)
radius = radius or 6
local positions = {}
for i = 1, count do
local angle = ((i - 1) / count) * 2 * math.pi
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
table.insert(positions, Vector3.new(x, 0, z))
end
return positions
end
local function updateWorkerPositions()
if not humanoidRootPart or not humanoidRootPart.Parent then return end
local positions = getWorkerRingPositions(#activeWorkers)
local orePositions = getOreRingPositions(#activeWorkers)
for i, worker in ipairs(activeWorkers) do
if worker and worker.Parent then
local humanoid = worker:FindFirstChildOfClass("Humanoid")
local rootPart = worker:FindFirstChild("HumanoidRootPart") or worker:FindFirstChild("Torso")
local targetOre = worker:FindFirstChild("TargetOre")
if humanoid and rootPart then
if targetOre and targetOre.Value and targetOre.Value:IsA("Model") and targetOre.Value.PrimaryPart then
local center = targetOre.Value.PrimaryPart.Position
local offset = orePositions[i]
local targetPos = center + offset
local lookDirection = (center - rootPart.Position).Unit
local lookCFrame = CFrame.new(rootPart.Position, rootPart.Position + lookDirection)
rootPart.CFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, lookCFrame.LookVector:Angle(Vector3.new(0, 0, -1)), 0)
humanoid:MoveTo(targetPos)
else
local offset = humanoidRootPart.CFrame.LookVector * -FOLLOW_DISTANCE
local targetPos = humanoidRootPart.Position + offset + humanoidRootPart.CFrame:VectorToWorldSpace(positions[i])
local distance = (rootPart.Position - targetPos).Magnitude
if distance > MAX_DISTANCE then
rootPart.CFrame = CFrame.new(targetPos)
else
humanoid:MoveTo(targetPos)
end
end
end
end
end
end
local function startWorkerUpdateLoop()
RunService.Heartbeat:Connect(function(dt)
lastUpdate += dt
if lastUpdate >= UPDATE_INTERVAL then
lastUpdate = 0
updateWorkerPositions()
end
end)
end
local function onWorkerAdded(worker)
print("[WorkerSystem] New worker added: ", worker.Name)
task.spawn(function()
local humanoid = worker:WaitForChild("Humanoid")
local rootPart = worker:WaitForChild("HumanoidRootPart")
if humanoid and rootPart then
humanoid.WalkSpeed = WALK_SPEED
table.insert(activeWorkers, worker)
positionWorkerBehindPlayer(worker)
refreshActiveWorkers()
end
end)
end
local function init()
local character = player.Character or player.CharacterAdded:Wait()
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
refreshActiveWorkers()
startWorkerUpdateLoop()
playerWorkerFolder.ChildAdded:Connect(onWorkerAdded)
player.CharacterAdded:Connect(function(newChar)
character = newChar
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
refreshActiveWorkers()
end)
end
init()