Using ROBLOX's WIKI page for magnitude I manged to make it work for bricks, now trying to find the magnitude between frames is not working as well :
WIKI : (http://wiki.roblox.com/index.php?title=Magnitude)
WORKING CODE :
local center = game.Workspace.center local short = game.Workspace.short local long = game.Workspace.long local magnitude = (center.Position - short.Position).magnitude print(magnitude)
Now the working code is ONLY for the bricks, but I am trying to make this move over to a ScreenGUI + ImageButton.
Would I need to make my own Vector3 values in order to get the position, because using [(frame.Position - frame2.Position).magnitude] gives me an error
This leads me to that fact I need to get in individual values of the UDim2 properties, which I don't know how to do and that's why I came here.
ERROR : magnitude is not a valid member, did you forget to capitalize the first letter? 13:30:37.945 - Script 'Players.Player1.PlayerGui.ScreenGui.ImageButton.Script', Line 5
You can use the Pythagorean theorem here. Simply plug in the X and Y values for the two objects .
dist = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
This formula only works if your parts are positioned using the Offset property.
local center = game.Workspace.center local short = game.Workspace.short local long = game.Workspace.long -- dist = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2) local magnitude = math.sqrt(((center.Position.X.Offset - short.Position.X.Offset) ^ 2) + ((center.Position.Y.Offset - short.Position.Y.Offset) ^ 2)) print(magnitude)