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

Is it possible to detect if another player is within a certain amount of studs from another player?

I am trying to have a force choke move for one of my characters in my game, and I only wanted it to work on certain characters that are within a certain amount of studs from the character.

I tried using a part and welding the part to the player and if the player was touching the part then they would be choked but this brought on more problems then progress.

So does anyone on here know if this is possible? Any tutorials or anything on it out there that I dont know of?

2 answers

✓ Accepted answer

Roblox made magnitude which is very nice for what you're doing http://wiki.roblox.com/index.php?title=Magnitude

But basically something easy would be like

players = game:GetService("Players")
hrp0 = players.LocalPlayer.Character.HumanoidRootPart
hrp1 = players.Player1.Character.HumanoidRootPart

local magnitude = (hrp0.Position - hrp1.Position).magnitude
if magnitude < 10 then
	-- choke player
end

2 comments

0

Oh Ive never even heard of that... Thanks dude! Your are a real legend, like I was gonna do a crazy complicated process to script it but it should be far easier now. Thanks so much :)

0

you're welcome I actually used magnitude for my own force choke script

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