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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Magnitude Problem?

Previous Thread :: Next Thread 
modulum is not online. 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 is not online. modulum
Joined: 11 Jul 2016
Total Posts: 242
15 Jul 2016 04:11 PM
+bump
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
xXTHEAWSOMEQWEENXx is not online. xXTHEAWSOMEQWEENXx
Joined: 12 Jun 2014
Total Posts: 5
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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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 is not online. 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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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 is not online. 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
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
15 Jul 2016 04:36 PM
break just breaks the inner-most loop, you're good.


Report Abuse
modulum is not online. modulum
Joined: 11 Jul 2016
Total Posts: 242
15 Jul 2016 04:38 PM
Good to know. Thanks guys!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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