What do you want to achieve? I want to have a script return false if “HitPlayer” is in “region”
What is the issue?
local region = Region3.new(Vector3.new(-17.183, 136.621, 331.28), Vector3.new(131.677, 136.721, 137.972))
function PlayerDamager:CanDamageHumanoid(DamagingPlayer,Humanoid)
local HitPlayer = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
if (something) then
return false
end
return true
end
I couldn’t find out how to check what the region of HitPlayer is
What solutions have you tried so far? I checked the DevHub and that actually helped me create the region3 value. I also did some looking on the DevForum but I couldn’t find anything like this. (Note: I don’t know if I have to say this but this script is from a free model sword that I have heavily modified)
local region = Region3.new(Vector3.new(-17.183, 136.621, 331.28), Vector3.new(131.677, 136.721, 137.972))
workspace:FindPartsInRegion3(region)
It prints nothing and because I don’t know what the name of the table is I can’t print it with “print”
Edit: I tried this
local region = Region3.new(Vector3.new(-17.183, 136.621, 331.28), Vector3.new(131.677, 136.721, 137.972))
local a = workspace:FindPartsInRegion3(region)
print (a)
it outputs " [table: 0x35dcc8106ecf418d]" and I don’t know what to do with this
If i recall right the “v” means Value and “i” means index
local region = Region3.new(Vector3.new(-17.183, 136.621, 331.28), Vector3.new(131.677, 136.721, 137.972))
local a = workspace:FindPartsInRegion3(region)
for i, v in pairs(a) do
print(v.Name)
end
I also don’t know what I should modify in this example, I also tried it as a Local and Server script but still no output.
uh, no I’m sure I have stuff in that area (such as Models) also I would like to remind myself and others that we are trying to check if a player (“HitPlayer”) is in “region”
edit: I also tried increasing the Y value of the 2nd region
while true do
local region = Region3.new(Vector3.new(-17.183, 136.621, 331.28), Vector3.new(131.677, 156.721, 137.972))
local a = workspace:FindPartsInRegion3(region)
for i, v in pairs(a) do
print(v.Name)
end
end
Sadly Roblox doesn’t offer a some sort of :IsInRegion() method, which would be very useful. Here is a manually written function that does this for you.
local NormalIds = Enum.NormalId:GetEnumItems()
function insideRegion(cf,size,point)
for i = 1, #NormalIds do
local enum = NormalIds[i]
local norm = Vector3.FromNormalId(enum)
local worldnorm = cf:vectorToWorldSpace(norm)
local distance = (norm * size/2).Magnitude
local planepoint = cf.Position + worldnorm * distance
if (point - planepoint):Dot(worldnorm) > 0 then
-- not inside region
return false
end
end
-- inside region
return true
end
Well this function is a rabbit hole to explain, you don’t really need to understand it in order to use, just use it like a normal built-in function added by roblox. The first parameter is the CFrame of the Region3 (region.CFrame) and 2nd is the Region3’s size (region.Size) and 3rd is the position of the object that you want to see if is in the region3.
if insideRegion(region.CFrame, region.Size, HitPlayer.Position) then
return false
end
Another simple thing to do would be this
for i, v in pairs(region:FindPartsInRegion3(region) do
if v == HitPlayer then
return false
end
end
return true
Basically loops through all the parts inside of the region3, and if the player is one of those parts meaning he’s in the region3, return false