Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
6 years ago

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
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 :) GottaHaveAFunTime 218 — 6y
0
you're welcome I actually used magnitude for my own force choke script Vulkarin 581 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You could find out how to get the magnitude right here: http://wiki.roblox.com/index.php?title=Magnitude

When you find that out just use an if statement to check if their magnitude is less then or equal to what you want it to be

Answer this question