Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 08 May 2014 06:43 PM |
How would I write a function that activates whenever a player's character comes within 10 Studs (x,y,z) of a certain part?
How would I likewise tell if the same player left the 10 Stud radius after entering?
DistanceFromCharacter reference:
http://wiki.roblox.com/index.php/DistanceFromCharacter_(Method) |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 08 May 2014 06:45 PM |
that method is dumb
local isWithinX = function(x, character, part) if (character:findFirstChild('Torso')) then return (character.Torso.Position - part.Position).magnitude <= 10 end end |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 08 May 2014 06:49 PM |
| Will this code sleep until the player enters within 10 studs of the part, and then activate once? |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 08 May 2014 07:05 PM |
local isWithinX = function(x, character, part) if (character:findFirstChild('Torso')) then return (character.Torso.Position - part.Position).magnitude <= 10 end end
game.Players.PlayerAdded:connect(function(p) while (wait()) do if (isWithinX(10, p.Character, Workspace.Part)) then -- change part -- do stuff here end end end) |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 08 May 2014 07:06 PM |
sorry:
game.Players.PlayerAdded:connect(function(p) local act = true
while (wait()) do if (act and isWithinX(10, p.Character, Workspace.Part)) then -- change part act = false
-- do stuff here else act = true end end end) |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|