getNearbyPlayers
Last updated
Last updated
Description
Returns a list of nearby players within a specified distance from the given player.
Parameters
source
(number): The server-side source ID of the player to check around.
distance
(number, optional): Maximum distance to consider as "nearby" (default: 10.0
).
⚠️ Note: This function currently filters players closer than
5.0
, regardless of the inputdistance
.
Return Value
Returns a table of nearby players with the following structure:lua\
{
id = citizenid,
name = "First Last",
source = source_id,
distance = number
}
Example Use Case
local nearby = ps.getNearbyPlayers(source, 10.0)
for _, player in ipairs(nearby) do
print(player.name .. " is nearby (" .. player.distance .. "m away)")
end
\