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
 

Need help with magnitude

Previous Thread :: Next Thread 
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 02:52 PM
local parts = game.Workspace.Map:getChildren()
for i = 1,#parts do
if (parts[i].Name ~= "Wall") then
if (parts[i].Name ~= "Water") then
if (parts[i].ClassName ~= "Model") then
if (parts[i].Position.Magnitude =< 8) then
script.Parent:MoveTo(parts[i])
end
end
end
end
end

Output doesn't say anything.

I just want it to move to whatever block is within 8 studs or whatever
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
22 Jul 2012 02:56 PM
You subtract two Vector3 values to find their Magnitude, as it compares the distance of the Position from (0, 0, 0).
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 02:56 PM
Oh I was looking at free models to see what magnitude was and all I see is magnitude so I thought it was a property of position
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 02:57 PM
So you mean to just


block.Position - block.Position???
Report Abuse
sam6175 is not online. sam6175
Joined: 16 Aug 2008
Total Posts: 1391
22 Jul 2012 02:58 PM
local check = script.Parent.Part
local parts = game.Workspace.Map:GetChildren()
for i = 1,#parts do
if (parts[i].Name ~= "Wall") and (parts[i].Name ~= "Water") and (parts[i].ClassName ~= "Model") then
if (parts[i].Position - check.Position).magnitude <= 8 then
script.Parent:MoveTo(parts[i])
end
end
end

change check to whatever part you want to check the magnitude from.
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 03:01 PM
Thankz
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 03:12 PM
Ok so sam, I ran into another problem (Sorry, I am trying to figure things out)

I realized there are many objects around it. (I made it so they turn red) I want it to single it out..

I try doing a math.random to choose one but that keeps saying I am attempting to get length of field?

local check = script.Parent.Parent.Stand
local parts = game.Workspace.Map:GetChildren()
for i = 1,#parts do
if (parts[i].Name == "GameBlock") and (parts[i].ClassName ~= "Model") then
if (parts[i].Position - check.Position).magnitude <= 16 then
s = math.random(1,#parts[i])

end
end
end

if s == 1 then
s.BrickColor = BrickColor.new("Bright red")
end


Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 03:17 PM
wait im an idiot i see my error
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 03:21 PM
agagagag ook I am so lost.

This is my new script

local check = script.Parent.Parent.Stand
local parts = game.Workspace.Map:GetChildren()
for i = 1,#parts do
if (parts[i].Name == "GameBlock") and (parts[i].ClassName ~= "Model") then
if (parts[i].Position - check.Position).magnitude <= 16 then
script.Parent.Parent:MoveTo(Vector3.new(math.random(1,#parts))).Position

end
end
end


Says I am missing an = at line 8 (Which is an end)

what
Report Abuse
SUBZEROBLOX is online. SUBZEROBLOX
Joined: 21 Nov 2010
Total Posts: 25642
22 Jul 2012 03:27 PM
1337777777777777777777777777777777777777777777777777777777777777
Report Abuse
Veerk is not online. Veerk
Joined: 20 Jun 2012
Total Posts: 1597
22 Jul 2012 03:38 PM
You increased my hopes... and dropped them.
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