Roblox orbital Gravity Problem

I used the way exactly like what they did in this post.
And I am facing the same problem. No matter how I try, it keeps disappear in a short time.

Is there a different way?

Here’s my script:

local TimeScale = game.Workspace.Stats.TimeScale.Value

local G = 6.67*10^-11

local Service = game:GetService(“RunService”)

local Childrens = game.Workspace:GetChildren()

for i = 1,#Childrens do

if Childrens[i].Name == “Planet” then

local BodyForce =“BodyForce”,script.Parent)

local TargetObject =“ObjectValue”,BodyForce)

TargetObject.Name = “Target”

TargetObject.Value = Childrens[i]

BodyForce.Parent = script.Parent




local BodyMovers = script.Parent:GetChildren()

for i = 1,#BodyMovers do

if BodyMovers[i].ClassName == “BodyForce” then

local Target = BodyMovers[i].Target.Value

local r = script.Parent.Position - Target.Position

local F = G*script.Parent:GetMass()*Target:GetMass()/r.Magnitude^2

BodyMovers[i].Force =F*r.Unit




Please reply, I can’t stay here for a day.

Please indent and format your code correctly using three " ` " symbols(left of the one key) to enclose your code block in. It will make it easier for people for us to read and ultimately get you more help.

1 Like

Oh, I figured out why it disappears.

1 Like

@DetailedModuler I think you should say why it’s disappearing. If you said it, you could help more scripts in the future.

1 Like

As my teacher said, if distance equals zero. There will be no answer.

Because you cannot divide zero.

6/0 = Nan