There was no way of explaining this in a title.
I have a function that can detect the nearest player from a block. Although, most of the time the nearest player from that block will be the “king” that controls the block. How can I make this function detect the nearest player that is not the “king”?
Note: ReplicatedStorage has a string value that says which player is the “king”, it changes when someone else becomes king.
Here is the function:
local function FindNearestPlayer(position)
local found
local last = math.huge
for _,plyr in pairs(game.Players:GetPlayers()) do
local distance = plyr:DistanceFromCharacter(position)
if distance < last then
found = plyr.Name
last = distance
end
end
return found
end
Thanks for any help!