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 » Scripters
Home Search
 

Re: Can anybody think of a more efficient way to do this:

Previous Thread :: Next Thread 
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
12 Jun 2016 11:19 PM
constantly check whether or not any player is within 10 units of a part,

here's my way, i'm not really liking the loop in my code :(
can anybody think of a better method?

while wait() do
for i,v in pairs(chrs) do --predefined list of characters
if (chr.Torso.Position - Center.Position).magnitude <= 10 then
print("my dude is in range!")
end
end
end
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
12 Jun 2016 11:20 PM
made a mistake, oops, don't point it out, still looking for better way though
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
12 Jun 2016 11:34 PM
b
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
12 Jun 2016 11:55 PM
Yeah do you really need to check the position of player 30 times a second?
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Jun 2016 12:13 AM
You could have a Vector3 value thats linked to the position of the character and use .Changed on that value.
Report Abuse
Aethex is not online. Aethex
Joined: 16 Oct 2011
Total Posts: 2193
13 Jun 2016 12:18 AM
Could also just put an invisible hit-box around that part, and then use the Touched event to see when a player is in range.
Report Abuse
Syntropy is not online. Syntropy
Joined: 16 Mar 2009
Total Posts: 2272
13 Jun 2016 12:24 AM
I'm using the same method in my game and it's fine. ^ Touched events are too glitchy and unreliable.
Report Abuse
Aethex is not online. Aethex
Joined: 16 Oct 2011
Total Posts: 2193
13 Jun 2016 12:31 AM
@Syntropy A stationary object running the Touched event? It's not glitchy nor unreliable. If this were actually the case, then all of those obbies with kill bricks would be terribly easy to beat. It's also even more likely to register considering the fact that, if large enough, the event will register for each individual limb on the character. I'm sure at least one would activate the Touched event.

If it's just one repeated loop to check for this, fine, but if you ever want to increase that amount, good luck. Try running code with a hundred simultaneous loops running to see if any character in the game is close to each and every part. The more players that joining will make it even worse.
Report Abuse
Syntropy is not online. Syntropy
Joined: 16 Mar 2009
Total Posts: 2272
13 Jun 2016 12:40 AM
When I tested it I had it check only for a part named torso. When it touches I print touch. When "TouchEnded" I print touchended. I take a single step in the region and get this in the output:

Touch
TouchEnded
Touch
TouchEnded
Touch

I lightly tap forward again:

TouchEnded
Touch
TouchEnded

This time the script is leaving off in the touch ended event and my character is still within the region. And yes I tried debouncing.
Report Abuse
Aethex is not online. Aethex
Joined: 16 Oct 2011
Total Posts: 2193
13 Jun 2016 12:47 AM
I have no idea how you tested that, please post the code. I created a somewhat large part and used this:

script.Parent.Touched:connect(function(hit)
if hit.Name == "Torso" then
print("touched");
end
end)

script.Parent.TouchEnded:connect(function(hit)
if hit.Name == "Torso" then
print("touchended");
end
end)

--

It only printed that it was touched once while walking in, and then only printed touchended once when walking out. It continued to work fine no matter what I did while inside of this part. It didn't matter if I slowly moved out with MouseLock while half of my Torso still remained it, it worked fine. I am unable to replicate your results, please help me to.
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