There’s several ways you can do this.
- Magnitude
- Touched Events
- GetTouchingParts
- Region3
Magnitude
local Players = game:GetService("Players")
local startPosition = Vector3.new() --where the 3d position should originate at
local maxDistance = 10 --how close a player must be to a specific position to get counted
local function checkDistance(position0, position1)
if ((position0 - position1).Magnitude < maxDistance) then
return true
end
return false
end
local function getPlayersFromStartPosition()
local playersInPlace = {}
for _,v in next, Players:GetPlayers() do
local character = v.Character
if (character) then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if (humanoidRootPart) then
if (checkDistance(startPosition, humanoidRootPart.Position)) then
table.insert(playersInPlace, v)
end
end
end
end
return playersInPlace
end
Touched Events
local part = workspace.Part --please point this to a specified part
local playersInPlace = {}; do --doing the magic
part.Touched:Connect(function(child)
for _,v in next, Players:GetPlayers() do
local character = v.Character
if (character) then
if (child:IsDescendantOf(character)) then
table.insert(playersInPlace, v)
end
end
end
end)
part.TouchEnded:Connect(function(child)
for _,v in next, Players:GetPlayers() do
local character = v.Character
if (character) then
if (child:IsDescendantOf(character) and table.find(playersInPlace, v)) then
table.remove(playersInPlace, table.find(playersInPlace, v))
end
end
end
end)
end
local function getPlayersInPlace()
return playersInPlace
end
GetTouchingParts
local Players = game:GetService("Players")
local part = workspace.Part --please set this to your correct target part
local function buildPlayersInPlace(fromPart)
local playersInPlace = {}
for _,child in next, fromPart:GetTouchingParts() do
for _,v in next, Players:GetPlayers() do
local character = v.Character
if (character) then
if (child:IsDescendantOf(character) and table.find(playersInPlace, v)) then
table.remove(playersInPlace, table.find(playersInPlace, v))
end
end
end
end
return playersInPlace
end
local function getPlayersInPlace()
return buildPlayersInPlace()
end
Region3
local origPosition = Vector3.new(0, 0, 0) --please set this to the appropriate position
local origSize = Vector3.new(4, 4, 4) --please set this to the appropriate size
local function findPartsInRegion3(partPosition, partSize)
local minPosition = partPosition - partSize/2
local maxPosition = partPosition + partSize/2
return workspace:FindPartsInRegion3(
Region3.new(
minPosition,
maxPosition
)
)
end
local function getPlayersInPlace()
local playersInPlace = {}
for _,v in next, findPartsInRegion3(origPosition, origSize) do
for _,x in next, Players:GetPlayers() do
local character = x.Character
if (character) then
if (v:IsDescendantOf(character)) then
table.insert(playersInPlace, x)
end
end
end
end
end
Please consider incorporating your own system. This is just a few examples of how you can do this process.