I'm trying to make it so that when I'm in game and theres a player like 10 meters nearby I can teleport behind them and use an attack
How to teleport to the nearest humanoid?
1 answer
ok so the following script should teleport the player to the back of the nearest other player that is not blocked by a wall or something and deal damage to it. Anyone with basic knowledge of roblox scripting(a.k.a better than ur knowledge on what questions are "legal" to ask in scriptintghelpers(dont worry im bad at this part too apparently)) should be able to reverse engineer this to fit their desires. Sorry i didnt elaborate im lazy but u should be able to grasp it(p.s im not bragging if u find it hard its just that ur not at that level yet(no offense) pls dont criticize me for bringing this up)
place it as a local script in starterpack:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
wait(1) -- load character
local char = player.Character
local char_root = char:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:connect(function()
local nearest_hum = math.huge
local target_root
local target_hum
for i, v in pairs(workspace:GetChildren()) do
local root = v:FindFirstChild("HumanoidRootPart")
local hum = v:FindFirstChild("Humanoid")
if root and hum and v ~= char then
local mag = (char_root.Position - root.Position).magnitude
if mag < 20 and mag < nearest_hum then
local obstructed = false
local ray = Ray.new(char_root.Position, (root.Position - char_root.Position).unit * 20)
local part = workspace:FindPartOnRay(ray, char, false, true)
if part then
if part.Parent ~= v then
obstructed = true
end
end
if obstructed == false then
nearest_hum = mag
target_root = root
target_hum = hum
end
end
end
end
if target_root and target_hum then
nearest_hum = math.huge
local behind = (target_root.CFrame * CFrame.new(0,0,-target_root.Size / 2)).p -- the behind lol
char_root.CFrame = CFrame.new(behind)
target_hum:TakeDamage(10)
end
end)
3 comments
also after testing it its kinda buggy. dont worry its something to do with the fact that it teleports the player to the exact "behind(line 48)" of the target but that can be altered easily(although at the moment im kinda busy so...). Btw i tried lerping cus it seemed cooler but i didnt seem to do it i think u need to offset it a bit for lerping but ye
im sure this thing can be improved but im lazy so its on to u!(ish)
connect is deprecated use Connect
This discussion is preserved as it was. New answers, comments, and votes are closed.

17 comments
Make a script.
Any attempts made?
https://scriptinghelpers.org/help/how-post-good-questions-answers
why'd u give
this isnt a request site
make a script then if theres any problems that make a question about it
dont just ask ppl to make one for u
https://scriptinghelpers.org/help/how-post-good-questions-answers
read that
EXpodo
look I have no idea on how to make it so I'm just asking for assistance ok? i didn't ask for your - reputation
dude
ok
@IthDithWite are u looking for a concept for it, or a script for it?
I’d at least research it elsewhere to have a basic sense if ur looking for a script.
lol
dude expo u dont ned to stick to the rules so bad(also dont downvote me for saying this)