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: teleport to nearest humanoid

Previous Thread :: Next Thread 
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
10 Apr 2016 05:54 PM
I have tried to make a script where if you press a key, then it teleports you a humanoid within a certain range
I have tried dat and i have been struggling for 3 days qq
so now, im asking if you guys can make one for me
i can post my script if you want to, though i doubt i can repair it
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
10 Apr 2016 06:11 PM
function FindNearestHumanoidLocation(point)
local points = {}
for _, a in pairs(Workspace:GetChildren()) do
if a:IsA("Model") and a:FindFirstChild("Humanoid") then
table.insert(points,a:GetModelCFrame().p)
end
end

local min = 0
local index = 0

for i=1, #points do
if i==1 then
min = (points[1] - point).Magnitude
index = 1
else
local dist = (point - points[i]).Magnitude
if dist < min then
min = dist
index = i
end
end
end
return points[index]
end

That function takes a Vector3 point and returns another Vector3 containing the location the humanoid closest the given point.

So,

When button is pressed {
player.Character:MoveTo(FindNearestHumanoidLocation(player.Character.Torso.Position) + Vector3.new(0,10,0))
}

Or something along those lines
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
10 Apr 2016 06:28 PM
oke

i shall try that out
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
10 Apr 2016 06:55 PM
wont work qq

heres what i got

Player = script.Parent.Parent
player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

function FindNearestHumanoidLocation(point)
local points = {}
for _, a in pairs(game.Workspace:GetChildren()) do
if a:IsA("Model") and a:FindFirstChild("Humanoid") then
table.insert(points,a:GetModelCFrame().p)
end
end

local min = 0
local index = 0

for i=1, #points do
if i==1 then
min = (points[1] - point).Magnitude
index = 1
else
local dist = (point - points[i]).Magnitude
if dist < min then
min = dist
index = i
Mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "g" then
player.Character:MoveTo(FindNearestHumanoidLocation(player.Character.Torso.Position) + Vector3.new(0,10,0))
end
end)
end
end
end
return points[index]
end
Report Abuse
NeonTurtle2001 is not online. NeonTurtle2001
Joined: 21 Jul 2013
Total Posts: 232
10 Apr 2016 06:58 PM
Small 15 robux Donation for my FPS project...


https://www.roblox.com/ShirtDonation-item?id=397084601
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
10 Apr 2016 07:01 PM
um wrong post man
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
10 Apr 2016 07:05 PM
i edited a little, but it still doesnt work
can someone tell me the error?




Player = script.Parent.Parent
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

function FindNearestHumanoidLocation(point)
local points = {}
for _, a in pairs(game.Workspace:GetChildren()) do
if a:IsA("Model") and a:FindFirstChild("Humanoid") then
table.insert(points,a:GetModelCFrame().p)
end
end

local min = 0
local index = 0

for i=1, #points do
if i==1 then
min = (points[1] - point).Magnitude
index = 1
else
local dist = (point - points[i]).Magnitude
if dist < min then
min = dist
index = i
Mouse.KeyDown:connect(function(Key)
Key = Key:lower()
if Key == "g" then
player.Character:MoveTo(FindNearestHumanoidLocation(player.Character.Torso.Position) + Vector3.new(0,10,0))
end
end)
end
end
end
return points[index]
end
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