leperdy
|
  |
| Joined: 07 Dec 2008 |
| Total Posts: 1406 |
|
|
| 21 Dec 2012 08:42 AM |
In my new game Universe Unlimited I am trying to program artificial gravity for planets, so that when ever a part gets close enough to the planet it gets a body position directing itself to the planets core, how ever I keep getting an error. Please help.
code:
function gravitise()
grav = instance.New("BodyPosition") grav.position = script.Parent.Core.Position grav.Parent = part
end
while true do local p = game.Workspace:GetChildren() if p.ClassName == Part then local reach = p.Position - script.Parent.Core.Position -- This is the broken line. if (reach).magnitude <= 1000 then gravitise(p) else wait(3) end end end
Error message:
08:36:11 - Workspace.Model.Script:16: bad argument #1 to '?' (Vector3 expected, got nil) 08:36:11 - Script "Workspace.Model.Script", Line 16 08:36:11 - stack end
|
|
|
| Report Abuse |
|
|
|
| 21 Dec 2012 08:47 AM |
On line 15 you forgot to put the "s around Part
Also, on what looks like line 5 there is a variable "part" which appears to be nil |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2012 08:48 AM |
| Also, if the part is within range then the script will not wait and the game will crash. |
|
|
| Report Abuse |
|
|
leperdy
|
  |
| Joined: 07 Dec 2008 |
| Total Posts: 1406 |
|
| |
|
|
| 21 Dec 2012 09:50 AM |
it is probably better to use a BodyForce. gravity is an acceleration.
the normal acceleration of gravity in ROBLOX is exactly 196.2 studs per seconds^2.
¬ LuaLearners Elite/Teacher(+3) ♣ SHG Scripter Tier-2 |
|
|
| Report Abuse |
|
|