Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

i am trying to make a region and the script wont work. why? pls help

I'm testing region3 for something and nothing is happening when I enter the region, it doesn't get past the for loop

local region = Region3.new(Vector3.new(17.938, 2.062, 214.438), Vector3.new(14.062, 11.938, 227.312)) -- 4, 10, 13
local Regionname = "Test"
local parter = game.Workspace.Partthing

while true do
	wait()
	local partsInRegion = workspace:FindPartsInRegion3(region, parter, 100)
	for i, part in pairs(partsInRegion) do -- it dont get past the for loop
		if part.Parent:FindFirstChild("Humanoid") then
			print("player found in region,".. Regionname ..":".. part.Parent.Name)
		end
	end
end

1 answer

✓ Accepted answer

I think your region is just the wrong size. It's easier to cast a region based on a part.

-- Your part
local Main = workspace.Main
-- Middle - HalfSize = Bottom Left corner, Middle + HalfSize = Top Right corner
local region = Region3.new(Main.Position - (Main.Size * 0.5), Main.Position + (Main.Size * 0.5) ) 

while true do
	local partsInRegion = workspace:FindPartsInRegion3(region, Main, 100)
	local SomeoneInRegion
	for _, part in pairs(partsInRegion) do
		local Player = part and part.Parent and game.Players:GetPlayerFromCharacter(part.Parent)
		if Player then
			print ( ('%s is in region'):format ( Player.Name )  )
			SomeoneInRegion = true
		end
	end
	Main.BrickColor = SomeoneInRegion and BrickColor.Green() or BrickColor.Red()
	wait()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.