I've created an orbital gravity script that is supposed to drag all objects in the 'Objects' folder to the biggest object. But my script only works when there is only one object to pull. Thank you!

local objects = workspace.Objects

while wait() do
	local G =  6.67430 * 10 ^ -11
	for x, object in pairs(objects:GetChildren()) do
		for y, otherObject in pairs(objects:GetChildren()) do
			if otherObject ~= object then
				r = otherObject.CFrame.p - object.CFrame.p
				F = G * object:GetMass() * otherObject:GetMass() / r.Magnitude  ^ 2
				object.BodyForce.Force = F * r.Unit
			end
		end
	end

1 comment

0

Isn’t there supposed to be an end to close the while wait loop?