How would I see if a player is 15 studs away from a part?

How would I see if a player is 15 studs away from a part and then print somthing?

Take the difference in their positions then take the Magnitude of that.

Hi👋,

To see if a player is 15 studs away from a part, code this:

local player = game.Players.LocalPlayer
local character = workspace:FindFirstChild(player.Name)
local hrp = character:WaitForChild("HumanoidRootPart") 

while wait() do
     local magnitudeBetweenBody = (workspace.Part.Position - hrp.Position).Magnitude

     if magnitudeBetweenBody >= 15 then
          print("15 studs away")
     end
end

:exclamation:Add this as a LocalScript inside wherever you want except ServerScriptService and ServerStorage.:exclamation:

Hope i helped! :sweat_smile:
Goodluck! :four_leaf_clover:

--Script in StarterCharacterScripts
local Character = script.Parent
local PrimaryPart = Character.PrimaryPart
local Part = workspace.Part -- The Part do you want

while task.wait() do
	if (Part.Position-PrimaryPart.Position).Magnitude >= 15 then
		print("Player is 15 studs away from the Part")
	end
end