modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
|
| 15 Jul 2016 04:03 PM |
Basically, I have this script that's supposed to print "in" whenever you're within 3 studs of one of the four ATM locations, and "out" whenever you're not. For some reason, if you get within the location, it prints:
in out out out in out out out
instead of just
in in in in in in in in
I'm not sure if I'm doing something wrong, or what.
local DetectionLocations = { game.Workspace.ATMs.det, game.Workspace.ATMs.det2, game.Workspace.ATMs.det3, game.Workspace.ATMs.det4, }
while wait() do for _,v in pairs(DetectionLocations) do local magnitude = (Character.Torso.Position - v.Position).magnitude if magnitude <= 3 then print("in") else print("out") end end end
|
|
|
| Report Abuse |
|
|
modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
| |
|
|
| 15 Jul 2016 04:19 PM |
You know that elevation matters too, right? You also know that the Torso generally stays about 3 studs above the ground, so your magnitude thing won't work. You might want to use HumanoidRootPart anyways, because it is the physics root for the character and isn't affected by animations.
|
|
|
| Report Abuse |
|
|
modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
|
| 15 Jul 2016 04:23 PM |
I didn't know that. Thanks for letting me know, though. I thought magnitude just checked 3 studs in all directions. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2016 04:25 PM |
It's saying that because there are four atms and you're only near one. If you were near all of them it would say
in in in in in in in in
|
|
|
| Report Abuse |
|
|
|
| 15 Jul 2016 04:25 PM |
Your script works correctly It's printing the results for all four ATMs so since you're only near one it prints in out out out |
|
|
| Report Abuse |
|
|
modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
|
| 15 Jul 2016 04:27 PM |
Ohhhhhhhhh. Okay. Should I just run four separate loops for each one? I feel like that would be efficient. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2016 04:29 PM |
Why not just break if they're near one?
while wait() do for _,v in pairs(DetectionLocations) do local magnitude = (Character.Torso.Position - v.Position).magnitude if magnitude <= 3 then print("in") break else print("out") end end end |
|
|
| Report Abuse |
|
|
modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
|
| 15 Jul 2016 04:32 PM |
I wouldn't have thought of that, thanks! That fixed it. I thought break completely breaks the loop though? So, like, it would completely stop the while loop until they respawn/the script is disabled then re-enabled? |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2016 04:36 PM |
break just breaks the inner-most loop, you're good.
|
|
|
| Report Abuse |
|
|
modulum
|
  |
| Joined: 11 Jul 2016 |
| Total Posts: 242 |
|
|
| 15 Jul 2016 04:38 PM |
| Good to know. Thanks guys! |
|
|
| Report Abuse |
|
|