How do you check if one of the players is near in one of the many parts, I’ve tried to use for i, loops I just couldn’t get it to work. Please help me if you know how to do it
local function FindNearestPartToPlayer(player)
local near_part, near_distance = nil, math.huge
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA('BasePart') then
local distance = player:DistanceFromCharacter(v.Position)
if distance < near_distance then
near_part = v
near_distance = distance
end
end
end
return near_part
end
local players = game:GetService("Players")
local part = workspace.Part -- change to name of part
for i, v in pairs(players:GetChildren()) do
local partPos = part.Position
local playerDistanceFromPart = v:DistanceFromCharacter(partPos)
print(playerDistanceFromPart)
end