Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to teleport to the nearest humanoid?

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

17 comments

1

Make a script.

0

Any attempts made?

0

why'd u give

0

this isnt a request site

0

make a script then if theres any problems that make a question about it

0

dont just ask ppl to make one for u

0

read that

0

EXpodo

0

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

0

dude

0

ok

0

@IthDithWite are u looking for a concept for it, or a script for it?

0

I’d at least research it elsewhere to have a basic sense if ur looking for a script.

0

lol

0

dude expo u dont ned to stick to the rules so bad(also dont downvote me for saying this)

1 answer

✓ Accepted 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

0

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

0

im sure this thing can be improved but im lazy so its on to u!(ish)

0

connect is deprecated use Connect

This discussion is preserved as it was. New answers, comments, and votes are closed.