The region is acting weird

Hi,
I was practicing creating Region3. The issue here is that when the region created, its field is weird.
The green plate is the field


Also, I am trying to make that when the player get into it take damage but even that doesn’t work. :confused: :slightly_frowning_face: :pensive:

Here is the script:

local tweening = game:GetService("TweenService")

local point1 = Instance.new("Part", workspace)
point1.Name = "point1"
point1.Anchored = true
point1.Transparency = 1
point1.Size = Vector3.new(1, 1 ,1)
point1.Position = Vector3.new(-90, 60.037, -32.5)
point1.CanCollide = false

local point2 = Instance.new("Part", workspace)
point2.Name = "point2"
point2.Anchored = true
point2.Transparency = 1
point2.Size = Vector3.new(1, 1 ,1)
point2.Position = Vector3.new(-66.5, 34.037, -2)
point1.CanCollide = false

local myregion = Region3.new(point1.Position, point2.Position)

local partforregion = Instance.new("Part", workspace)
partforregion.CanCollide = false
partforregion.Anchored = true
partforregion.Material = Enum.Material.ForceField
partforregion.BrickColor = BrickColor.new("Lime green")
partforregion.Transparency = 0
partforregion.Size = myregion.Size
partforregion.CFrame = myregion.CFrame

local ignoredParts = {point1,point2,partforregion}

while wait(1) do
	local usedpartsforregion = workspace:FindPartsInRegion3WithIgnoreList(myregion, ignoredParts, math.huge)
	for i, object in ipairs(usedpartsforregion) do
		if object.Parent:FindFirstChild("Humanoid") ~= nil then
			local char = object.Parent
			char.Humanoid:TakeDamage(5)
		end
	end
end

So from my perspective, I don’t see that you use any Touched function in this source code so we will have to add one in before checking if Humanoid exists on touch. Here is a potential fix for decreasing health of the player:

while wait(1) do
	local usedpartsforregion = workspace:FindPartsInRegion3WithIgnoreList(myregion, ignoredParts, math.huge)
	for i, object in ipairs(usedpartsforregion) do
      object.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") ~= nil then
			local char = hit.Parent
			char:FindFirstChild("Humanoid"):TakeDamage(5)
		end
       end
	end
end
1 Like

Yeah, but I mean when I get into the region the player will take damage. I made the part so it can act as the field of region but as you can see the field is not like I expected.