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: Distance-calculated key door

Previous Thread :: Next Thread 
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
15 Feb 2015 06:50 PM
What I want is to make a door that when you stand close to it, press E, it executes a pre-defined function. for example:

Player 1 walks up to the door, has a distance of 5 or less to the door, and presses E, he gets teleported far away. He presses E again, nothing happens.

Player 2 walks up to the door and does the same process. The same effect happens to Player 2 as to Player 1.


I have absolutely no clue how to do the magnitude/switching part of the script. I do have this:

mouse = player:GetMouse()

if statement for when the nearest players is 5 or less studs away from the door

mouse.KeyDown:connect(function(key)
key = key:lower()
if key=="e" then
player.Character.Torso.CFrame = workspace["pos1"].CFrame.Vector3.new(0,5.5,0)
end
end)

Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
15 Feb 2015 06:52 PM
(door.Position-workspace.Eternalfireeater.Torso.Position).magnitude
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
15 Feb 2015 07:05 PM
@Eternalflamer
Why not explain

@OP
magnitude is the name for vector distance.
We would find the distance between point a and b by drawing a triangle between point A and B.

|\
| \
|A \C
|___\
B

The top acute angle represents your destination.
The bottom right acute represents your position.

Using the Pythagorean theorem, you can calculate the hypotenuse.
The forumla is C^2=A^2+B^2

Which you would solve it like this...
local Distance = math.sqrt(A*A+B*B)
or
local Distance = math.sqrt(math.pow(A,2)+math.pow(B,2))

You need to subtract two vectors from eachother to get the vector you will use.

local Point_A = Vector3.new(5,5,5)
local Point_B = Vector3.new(5,6,5)

local Point = Point_A - Point_B

local Distance = math.sqrt(Point.X*Point.X+Point.Y*Point.Y+Point.Z*Point.Z)

You will need to call math.abs() to make this a non-negative number because thats what it is.

OR

you can simply type...

local Distance = (Point_A - Point_B).magnitude
Report Abuse
juniorjfive is not online. juniorjfive
Joined: 05 Jan 2010
Total Posts: 671
15 Feb 2015 07:07 PM
Make part's in the workspace called "Doors", the script will do the rest.

local Player = game:service'Players'.LocalPlayer
local Mouse = Player:GetMouse();

local Character = Player.Character
local Humanoid = Character:WaitForChild( 'Humanoid' );
local Torso = Character:WaitForChild( 'Torso' );

local Doors = { }
local KeyActivation = 'e'
local Trials = 0
local MaxDistanceFromDoors = 5

for i,v in next, workspace:GetChildren() do
if v.Name == 'Door' then
table.insert( Doors, v )
end
end
local function TeleportPlayer()
Torso.CFrame = workspace["pos1"].CFrame * CFrame.new(0, Torso.Size.Y, 0)
end

Mouse.KeyDown:connect(function( Key )
if Key == KeyActivation then
Trials = Trials + 1
if Trials <= 1 then
for i,v in next, Doors do
if (Torso.CFrame.p - v.CFrame.p).magnitude <= MaxDistanceFromDoors then
TeleportPlayer()
end
end
end
end
end)
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
15 Feb 2015 08:23 PM
I figured these things,
but how do I solve that the script always lets only YOU do it, and not the next player?

The problem is that I need the every player able to do it.
Report Abuse
lsp425 is not online. lsp425
Joined: 10 Dec 2011
Total Posts: 603
15 Feb 2015 09:16 PM
Have it so that it loops through all the players.
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
15 Feb 2015 09:19 PM
lolwot?
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