Alfa247
|
  |
| Joined: 15 Jan 2010 |
| Total Posts: 118 |
|
|
| 09 Oct 2016 07:09 AM |
Just like when a block is hit. game.Workspace.Baseplate.Touched:connect(function() --CODE end)
Is there on for when a player is within a certain magnitude in an area without putting it through a while script.
while wait(.1) do players = game.Players:GetChildren() for i,v in pairs(players) do player_torso = v.Character.Torso player = v.Character
if ((script.Parent.Torso.Position-player_torso.Position).magnitude <= 15) then
print ("TEXT HERE") |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2016 08:56 AM |
| You could try creating an invisible sphere with a touch event. |
|
|
| Report Abuse |
|
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 09 Oct 2016 09:32 AM |
you could do .Changed on the player's position (it will run every time you move) then you check if the character is within distance of the object |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2016 09:49 AM |
| That would work, yet that might be pretty laggy, especially when there are multiple players. While my solution will fire only once. |
|
|
| Report Abuse |
|
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
|
| 09 Oct 2016 11:14 AM |
| it's a pretty small calculation... you wont ever notice it |
|
|
| Report Abuse |
|
|
Gentaurg
|
  |
| Joined: 19 Mar 2011 |
| Total Posts: 8648 |
|
| |
|
|
| 09 Oct 2016 11:23 AM |
You could calculate it yourself using removing sqrt from it. Since it isn't useful to have the actual stud magnitude unless your displaying it to the player.
So... something like...
local v = pos2-pos1 local mag = v.x*v.x+v.y*v.y+v.z*v.z
if dist^2 < mag then --in circle end |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2016 11:31 AM |
| Btw my thing was just speeding up the on update solution, a sphere with OnTouch event though is probably the best solution. |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2016 03:37 PM |
| Or a combination of both? When the player hits the sphere a loop starts, calculating the distance and sending it to where ever it's needed, and the loop breaks when touch has ended. |
|
|
| Report Abuse |
|
|