|
| 17 Mar 2016 07:18 AM |
while true and wait() do if script.check.Value == true then for i,a in pairs (game.Workspace[script.setstat.Value].GroupA:GetChildren()) do if a:IsA("BasePart") then local mag = (a.Position - move.Position).magnitude -- Right here, How would I get the least mag? end end elseif script.check.Value == false then wait() end end
-- How would I get the least mag? from those values it's getting from the mag? |
|
|
| Report Abuse |
|
|
WoolHat
|
  |
| Joined: 19 May 2013 |
| Total Posts: 1873 |
|
|
| 17 Mar 2016 07:22 AM |
while wait() do if script.check.Value then local currentmin = math.huge() for i,a in pairs (game.Workspace[script.setstat.Value].GroupA:GetChildren()) do if a:IsA("BasePart") then local mag = (a.Position - move.Position).magnitude currentmin = math.min(currentmin,mag) end end print(currentmin) end end |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2016 07:35 AM |
| : attempt to call field 'huge' (a number value) |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2016 07:36 AM |
| Sorry, that is on the line with the math.huge() |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2016 08:30 AM |
make math.huge() into math.huge
no brackets |
|
|
| Report Abuse |
|
|
R4G3N4R0K
|
  |
| Joined: 16 Feb 2016 |
| Total Posts: 74 |
|
|
| 17 Mar 2016 09:57 AM |
while true and wait() do local dist = 99 -- THE MAX MAG DISTANCE if script.check.Value == true then for i,a in pairs (game.Workspace[script.setstat.Value].GroupA:GetChildren()) do if a:IsA("BasePart") then local mag = (a.Position - move.Position).magnitude if mag <= dist then dist = mag end end end elseif script.check.Value == false then wait() end end |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2016 10:20 AM |
I thank you people for caring to reply, but I don't think you're getting what I'm asking for.
The script is for docking. The "station" will have 4 max docking point a's.
For example. the structure would be something like
StationName(Model) -DockingPoints(Model) --PointA(Model) ---PointAA(Part) ---PointBA(Part) ---PointCA(Part) ---PointDA(Part) --PointB(Model) ---PointAB(Part) ---PointBB(Part) ---PointCB(Part) ---PointDB(Part)
Now, the script gets the children in PointA, and gets the math, but needs to get the one that is the least furthest away, and for right now "Print" that value. for example, it would print PointCA in the output(if it was the closest point). However, I'm leaving it at as a "GetChildren" because I want to be able to use the script- for multiple stations without having to do a custom script for each one.
Then It moves to that point, gets its counter part (being PointCB) and move to that one. |
|
|
| Report Abuse |
|
|
R4G3N4R0K
|
  |
| Joined: 16 Feb 2016 |
| Total Posts: 74 |
|
|
| 17 Mar 2016 10:12 PM |
| Mine will find the nearest one. :3 |
|
|
| Report Abuse |
|
|
WoolHat
|
  |
| Joined: 19 May 2013 |
| Total Posts: 1873 |
|
|
| 18 Mar 2016 05:09 AM |
Revised, so it returns to actual closest part,instead of the smallest number. Also, not sure why you have this in a while loop. But I'll just comment it out
--while wait() and script.check.Value do local currentmin = math.huge() local nearestblock for i,a in pairs (game.Workspace[script.setstat.Value].GroupA:GetChildren()) do if a:IsA("BasePart") then local mag = (a.Position - move.Position).magnitude currentmin = math.min(currentmin,mag) if currentmin == mag then nearestblock = a end end end return nearestblock --end |
|
|
| Report Abuse |
|
|