Hello, I’m trying to find players in a Region3. But only the characters are detected, not the players.
Script in workspace.SoundPart:
local Players: Players = game:GetService("Players")
local soundEvent: RemoteEvent = game:GetService("ReplicatedStorage").SoundEvent
local soundPart: Part = script.Parent
local vectorMin: Vector3 = Vector3.new(soundPart.Position.X - (soundPart.Size.X / 2), soundPart.Position.Y - (soundPart.Size.Y / 2), soundPart.Position.Z - (soundPart.Size.Z / 2))
local vectorMax: Vector3 = Vector3.new(soundPart.Position.X + (soundPart.Size.X / 2), soundPart.Position.Y + (soundPart.Size.Y / 2), soundPart.Position.Z + (soundPart.Size.Z / 2))
local region3: Region3 = Region3.new(vectorMin, vectorMax)
while true do
local partsInRegion3 = workspace:FindPartsInRegion3(region3)
local playersInRegion3 = {}
for index: number, basePart: BasePart in partsInRegion3 do
if basePart.Parent and basePart.Parent:FindFirstChildOfClass("Humanoid") then
local character: Model = basePart.Parent :: Model --Character exists, I already printed it.
local player: Player? = Players:GetPlayerFromCharacter(character) --Does not print?
if player and not table.find(playersInRegion3, player) then
table.insert(playersInRegion3, player)
end
end
end
print(playersInRegion3)
task.wait(1)
end