Never know it does not work anymore, yes it still can detect a part, but the whitelist is not working. Now, what should I use? I will not provide code here you can try it yourself. Cuz this change affects my whole game like a lot
It’s called scripting support for a reason. No code no help
There’s no context so can’t provide a sound solution to your specific use case but if we’re addressing the grand scope here then I think you should look to GetPartBoundsInBox and OverlapParams. The former supersedes FindPartsInRegion3[x] and the latter allows you to modify how the spatial query is performed, including a FilterType property (which you’d be using Enum.FilterType.Whitelist for this).
EDIT: Wrong API name, link remains the same.
Well, it looks like the FindPartsInRegion3 functions are broken, they are deprecated after all and you shouldn’t be using them. Use workspace:GetPartBoundsInBox instead
Sorry, I’m a bit salty cuz it cause me a lot of trouble, so here’s the code. Ignore the unnecessary stuff cuz some of them I used it in my game. It worked before, but today it just doesn’t work and I haven’t changed anything.
function combatHelp:GetEnemyInRegion(player, startVector, endVector, limit) --> tables contains other player HumanoidRootPart
if limit == nil then
limit = 20
end
local all_players = Players:GetChildren()
local all_players_character = {}
for _, other_player in pairs(all_players) do
if other_player ~= player then
local char = other_player.character
if char then
local hmr = char:FindFirstChild("HumanoidRootPart")
if hmr then
table.insert(all_players_character, hmr)
end
end
local NPCchar = {}
for _, name in pairs(NPC_NAME) do
if workspace:FindFirstChild(other_player.Name .. "%" .. name) then
table.insert(NPCchar, workspace:FindFirstChild(other_player.Name .. "%" .. name))
end
end
if NPCchar then
for _, v in pairs(NPCchar) do
local hmr = v:FindFirstChild("HumanoidRootPart")
if hmr then
table.insert(all_players_character, hmr)
end
end
end
end
end
local region = Region3.new(startVector, endVector)
local allPart = workspace:FindPartsInRegion3WithWhiteList(region, all_players_character, limit)
return allPart
end
The allPart should be table value contain only other player humanoid root part in the game, but somehow it includes everything that inside the region (even tho I used whitelist) It just happen today, yesterday I tested with the same code and it worked fine. So, I guess it’s broken as @Judgy_Oreo said.
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local run = game:GetService("RunService")
local part = workspace:WaitForChild("Part")
local region = Region3.new(Vector3.new(part.Position.X - part.Size.X/2, part.Position.Y - part.Size.Y/2, part.Position.Z - part.Size.Z/2), Vector3.new(part.Position.X + part.Size.X/2, part.Position.Y + part.Size.Y/2, part.Position.Z + part.Size.Z/2))
run.RenderStepped:Connect(function()
local regionParts = workspace:FindPartsInRegion3WithWhiteList(region, {character})
for _, regionPart in ipairs(regionParts) do
print(regionPart.Name)
end
end)
It’s working fine on my end.
The script is only printing the names of descendants of the local player’s character model.
and here’s a server-side implementation:
local players = game:GetService("Players")
local run = game:GetService("RunService")
local part = script.Parent
local region = Region3.new(Vector3.new(part.Position.X - part.Size.X/2, part.Position.Y - part.Size.Y/2, part.Position.Z - part.Size.Z/2), Vector3.new(part.Position.X + part.Size.X/2, part.Position.Y + part.Size.Y/2, part.Position.Z + part.Size.Z/2))
local characters = table.create(players.MaxPlayers)
run.Heartbeat:Connect(function()
for _, player in ipairs(players:GetPlayers()) do
local character = player.Character
if character then
table.insert(characters, character)
end
end
if #characters <= 0 then return end
local regionParts = workspace:FindPartsInRegion3WithWhiteList(region, characters)
for _, regionPart in ipairs(regionParts) do
print(regionPart.Name)
end
table.clear(characters)
end)
This deprecated function definitely stopped working and broke my game’s lobby… I’ll be using @colbert2677 Solution via GetPartBoundsInBox
After replacing this function, my game completely came back to life… after days of optimizing to figure out why there was so much lag and and hangups in the processes that seemed to make no sense… I replaced all the deprecated spawn functions with coroutines, and the FindInRegionWithWhiteList with GetPartBoundsInBox and viola!!! my game is alive and working better than ever with all the optimizations I did.
Apparently, when using this function with 4 buses in my lobby with multiple queries to find players on the bus, there must be a new memory leak… a game I have published that had worked for months, suddenly started getting downvotes, when I realized it was broken, and it took days to figure out this was the actual problem. Thanks to everyone for their help.