✓ Accepted answer
-- EDIT --
A way you can make your code ignore the character is by using the ignoreDescendentsInstance argument of the FindPartsInRegion3 function. This argument should be an instance, every descendant(everything in it) will be ignored from the returned table but will still count torwards the maxParts argument. So, your code SHOULD work but since for some odd reason it isn't then i'm going to suggest an alternative;
There is no real way to whitelist a Region3 range table effectively without the development of a custom Region3 system.. so an alternative for you is while you're iterating through the partsInRange table, you can check if the current index's parent is equal to the character. If it isn't then add Velocity, if it is then don't.
But just doing that won't stop hats or tools from gaining velocity.. so how about we add another conditional to check if the part's Name is Handle
local player = game.Players.LocalPlayer
local char = player.Character
local region3 = Region3.new(
Vector3.new(char.Torso.Position.X -20, char.Torso.Position.Y-5, char.Torso.Position.Z -20),
Vector3.new(char.Torso.Position.X+20, char.Torso.Position.Y+10, char.Torso.Position.Z +20)
)
local partsInRange = game.Workspace:findPartsInRegion3(region3, char, 20)
for _, part in pairs(partsInRange) do
if part.Parent ~= char and part.Name ~= 'Handle' then
local dist = (part.Position - char.Torso.Position).magnitude
part.Velocity = char.Torso.CFrame.lookVector * dist
end
end
--EDIT--
Another way you could do this is by using the IsDescendantOf function for the checking while iterating through the table..
for _, part in pairs(partsInRange) do
if not part:IsDescendatOf(char) then
local dist = (part.Position - char.Torso.Position).magnitude
part.Velocity = char.Torso.CFrame.lookVector * dist
end
end
--EDIT--
And finally, there's another option.. you could look into the FindPartsInRegion3WithIgnoreList function. More info here.
Sorry for all the edits, i'm just researching some stuff and editing when I come across something else that could help you solve your problem.
4 comments
thanks Goulstem, I'll be sure to try that
but if there is no way to whitelist a region 3 table then what doeswhat does ignore descendants actually do
It does ignore descendants. But the argument has to be used as an instance - meaning that all descendants of that instance would be ignored, and this isn't always going to be the case that you want. (That moment when goulstem realizes he was wrong). Lol let me edit my answer(:
Hm.. this is tough. The ignoreDescendants argument SHOULD work. But since it doesn't(I just tested it in studio as well) then I guess you have to use my suggested alternative.