How to check if a player is within a certain distance from your character?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so that if a player is within a certain distance from your character (for example 10 studs) then it will print the other players name, and if the other player is not within 10 studs then it prints something like no player is within 10 studs from you.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know anything with magnitude.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum.

You can use this script

local function CheckDistance(Plr1, Plr2, Distance)
 if (Plr1.Character.HumanoidRootPart.CFrame.Position - Plr2.Character.HumanoidRootPart.CFrame.Position).Magnitude <= Distance then
  return true
 else
  return false
 end
end

I haven’t tested the script so it might contain error, if you won’t get the fix you can put it here and ill fix it

1 Like

Ill try this asap. And ill let u know if it works

1 Like

Also guys, how would i be able to tell if there are 2 players within a certain distance.

you can use this same script for that too