generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Artificial gravity help

Previous Thread :: Next Thread 
leperdy is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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 is not online. leperdy
Joined: 07 Dec 2008
Total Posts: 1406
21 Dec 2012 08:50 AM
kk, thanks.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image