Alternative to Region3?

Since I think region3 is better for me so I decided use it anyways, but I don’t understand what’s wrong with the code?
For e.x you can walk at medium part which is works weird, the large is decent, small is decent too!

Anyone have a good alternative to use?

function isOn(part,plr)
	local min = part.Position - (.5 * part.Size)
	local max = part.Position + (.5 * part.Size)	
	local region = Region3.new(min,max):ExpandToGrid(1)
	while task.wait() do
		local parts = game.Workspace:FindPartsInRegion3(region,part,math.huge)
		for i,v in pairs(parts) do
			local parent = v.Parent
			if parent:FindFirstChild("Humanoid") and parent:FindFirstChild("Humanoid").MoveDirection ~= Vector3.new(0,0,0) and parent:FindFirstChild("Humanoid").Health > 0 then
				part.BrickColor = BrickColor.new("Really black")
				plr.object.Value = part
				break
			else
				part.BrickColor = BrickColor.new("Institutional white")
				if plr.object.Value == part then
					plr.object.Value = nil
				end
			end
		end
		if #parts == 0 then
			part.BrickColor = BrickColor.new("Institutional white")
		end
	end
end

for _, v in pairs(workspace.level10:GetChildren()) do
	v.Touched:Connect(function(hit)
		if hit.Parent.Humanoid then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.object.Value = v
			isOn(v,player)
		end
	end)
end

PartColor.rbxl (26.9 KB)

I use GetTouchingParts a lot, as it’s easier to work with than Region3. You can change the “region” simply by resizing the part.
GetTouchingParts returns a table of parts interacting with a specified part. If you needed to access the interacting parts, you can simply unpack the table.
Though if atleast one of the parts is CanCollide = false, it will not be detected unless you implement this simple trick.

1 Like

Check out

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/GetPartBoundsInBox

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/GetPartBoundsInRadius

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/GetPartsInPart

3 Likes