Hey, I am having a bit of trouble figuring out how to make a script where it checks if there are parts within a certain radius of your tool.
local ignoreSurroundingsList = {"Torso", "Head", "LeftLeg", "RightLeg", "LeftArm", "RightArm"}
function checkSurroundings(plr)
script.Parent.Handle.CanCollide = true
local Point1 = Vector3.new(0,0,0)
local Point2 = Vector3.new(10,10,10)
local Region = Region3.new(Point1,Point2)
for _,Part in pairs(script.Parent.Handle:GetTouchingParts(Region,nil,math.huge)) do
for i,v in ipairs(ignoreSurroundingsList) do
if Part.Name:lower() ~= v:lower() then
print(Part.Name)
script.Parent.Handle.CanCollide = false
return true
end
end
end
script.Parent.Handle.CanCollide = false
return false
end
The code above is what I have, but my issue is that the output (being printed out) is always Torso being within the radius. I believe this means that I’m doing something wrong where it’s checking to see if its white-listed in the “ignoreSurroundingsList”. What am I doing incorrect here? Why does it keep printing Torso?
Earlier I was using FindPartsInRegion3, but I couldnt get it to work. I think it’s because of my lack of understanding of how this is supposed to be used. Ideally, I wanted to do:
for _,Part in pairs(script.Parent.Handle:FindPartsInRegion3(Region,nil,math.huge)) do
However, I think I am limited to just to using Workspace if I use that.
Does anyone have an idea on how I can tackle this problem?