How to get the distance of every player individually

Hi im trying to make a script where all players get a highlight if certain distance is met but I can’t just figure it out, i tried this only to realize it wouldnt work

	for _, players in game.Workspace.MorhpedPeople:GetChildren() do
		if (script.Parent:WaitForChild("HumanoidRootPart").Position - players:WaitForChild("HumanoidRootPart").Position).Magnitude <= 25 then
			game.ReplicatedStorage.Storage.CrystalHL:Clone().Parent = players
	end
		end
			end

Any help is appreciated

I have a lot of questions/concerns here.

  1. Is this a server or local script?
  2. The indentation is off. The code snippet should look like this:
for _, players in game.Workspace.MorhpedPeople:GetChildren() do
	if (script.Parent:WaitForChild("HumanoidRootPart").Position - players:WaitForChild("HumanoidRootPart").Position).Magnitude <= 25 then
		game.ReplicatedStorage.Storage.CrystalHL:Clone().Parent = players
	end
end
  1. How often are you running this script? Is this in a run service event? A while loop?
  2. Can you be more specific with what you want? Based on the code, I’m guessing that you want a player to be highlighted if they are more than 25 studs away from the local player.
  1. Local script
  2. This script runs every time an input is done
  3. Yes, what you described is true
local CrystalHL = game.ReplicatedStorage
	:WaitForChild("Storage"):WaitForChild("CrystalHL")
local peeps = game.Workspace:WaitForChild("MorhpedPeople")
for _, peep in pairs(peeps:GetChildren()) do
	local hrp = peep:WaitForChild("HumanoidRootPart")
	if(script.Parent:WaitForChild("HumanoidRootPart").
		Position - hrp.Position).Magnitude <= 25 then
		CrystalHL:Clone().Parent = peep
	end
end

Okay, the code @2112Jay posted should mostly get you there. It just loops through all players and gives them another highlight every time an input is processed.

You may want to check another 2 things:

  1. Only add a highlight if the player doesn’t already have a highlight
  2. Remove highlights from players if they are outside the range
local CrystalHL = game.ReplicatedStorage
	:WaitForChild("Storage"):WaitForChild("CrystalHL")
local peeps = game.Workspace:WaitForChild("MorhpedPeople")
for _, peep in pairs(peeps:GetChildren()) do
	local hrp = peep:WaitForChild("HumanoidRootPart")
	local existingHL = peep:FindFirstChild("CrystalHL")
	local dist = (script.Parent:WaitForChild("HumanoidRootPart")
		.Position - hrp.Position).Magnitude
	if dist <= 25 and not existingHL then
		CrystalHL:Clone().Parent = peep
	elseif dist > 25 and existingHL then
		existingHL:Destroy()
	end
end

Thank you all for the help! This will do!