Hi all, when I use bodyposition sometimes it works and puts the part I want into the correct position but sometimes the part just falls out the world and is affected by the script or the bodyposition I’m not sure why it does this.
Here is the code that updates the bodyposition
RunService.RenderStepped:Connect(function()
if LocalPlayer.Character then
local Character = LocalPlayer.Character
if Character:FindFirstChild("Humanoid") then
if Character.Humanoid.Health > 0 then
local Counter = 1
local LengthofList = Length(ListofPets)
for _,each in pairs(ListofPets) do
print(Counter)
if LengthofList == 1 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(7,0,0)
elseif LengthofList == 2 then
if Counter == 1 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(7,0,0)
else
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-7,0,0)
end
elseif LengthofList == 3 then
if Counter == 1 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(7,0,0)
elseif Counter == 2 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-7,0,7)
else
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-7,0,-7)
end
elseif LengthofList == 4 then
if Counter == 1 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(7,0,7)
elseif Counter == 2 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-7,0,7)
elseif Counter == 3 then
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-7,0,-7)
else
each.PrimaryPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(7,0,-7)
end
end
each.PrimaryPart.BodyGyro.CFrame = CFrame.new(each.PrimaryPart.Position,each.PrimaryPart.Position + Vector3.new(Character.PrimaryPart.CFrame.LookVector.x,0,Character.PrimaryPart.CFrame.LookVector.z))
Counter += 1
-- each.PrimaryPart.BodyGyro = CFrame.new()
end
end
end
end
end)