|
| 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
|
  |
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 10 Apr 2016 06:58 PM |
Small 15 robux Donation for my FPS project...
https://www.roblox.com/ShirtDonation-item?id=397084601 |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|