Hello, I was working on a pet following system but for some reason when I play it’s not as smooth as when it’s from a local script but I want players to see everytone’s pets. Here is how it looks from a server script:
My code (server script):
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local character = char
local hrp = character:WaitForChild("HumanoidRootPart")
local parts = {}
local numberOfParts = 8
for _ = 1, numberOfParts do
table.insert(parts, Instance.new("Part"))
end
for i, part in pairs(parts) do
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
end
local fullCircle = 2 * math.pi
local radius = 10
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
game:GetService('RunService').Heartbeat:Connect(function()
for i, part in pairs(parts) do
local angle = i * (fullCircle / #parts)
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, drift, z)).p
local lookAt = hrp.Position
part.CFrame = part.CFrame:Lerp(CFrame.new(position, lookAt), .1)
end
end)
end)
end)
The code for generating parts around the player is from the solution of this post:
Thank you!