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 » Scripting Helpers
Home Search
 

Re: DistanceFromCharacter

Previous Thread :: Next Thread 
Soybeen is online. 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 is not online. 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 is online. 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 is not online. 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 is not online. 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 is online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
08 May 2014 07:10 PM
Thanks, I appreciate it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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