Code:
local runService = game:GetService("RunService")
local character = script.Parent
local rootPart = character.HumanoidRootPart
local pets = {}
local spacing = 4
runService.Heartbeat:Connect(function(deltaTime)
local columns = math.floor(math.sqrt(#pets))
local offset = Vector3.new(-columns / 2 * spacing + spacing / 2, 0, 4)
for i, pet in ipairs(pets) do
i -= 1
local x = i % columns
local z = math.floor(i / columns)
local targetPosition = rootPart.Position + offset + Vector3.new(x, 0, z) * spacing
if pet:FindFirstChild("BodyPosition") then
pet.BodyPosition.Position = targetPosition
end
if pet:FindFirstChild("BodyGyro") then
pet.BodyGyro.CFrame = rootPart.CFrame
end
end
end)
workspace.PlayerPets:WaitForChild("AbyssalBl4de").ChildAdded:Connect(function(Child)
Child:SetPrimaryPartCFrame(rootPart.CFrame)
table.insert(pets, Child.PrimaryPart)
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.MaxForce = Vector3.new(4000, 4000, 4000)
bodyPosition.P = 2000
bodyPosition.D = 100
bodyPosition.Position = Child.PrimaryPart.Position
bodyPosition.Parent = Child.PrimaryPart
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
bodyGyro.P = 3000
bodyGyro.CFrame = Child.PrimaryPart.CFrame
bodyGyro.Parent = Child.PrimaryPart
end)
workspace.PlayerPets:WaitForChild("AbyssalBl4de").ChildRemoved:Connect(function(Child)
table.remove(pets, table.find(pets, Child.PrimaryPart))
end)
Hello,
I want the bodyposition to always be behind the character, how can i make that?