Region 3 dosen't detect character

Hello! So I’ve been working on this project, and I get this weird bug that I don’t really understand why it happened. I’m making a Roblox robbing system where the player/s can rob different places and earn money out of it. The first player that is inside the region box is the host. the host can press “Begin robbing” whenever his crew members are inside the box with him. Now here is the weird thing, when playing on player 2 and having player 2 as a host, the script detects both player1 and player2 as you can see on the server console on the video. But having player1 as a host only detects itself and no one else. All of the robbers get stored on a table.
Any suggestions on how to fix this help!

External Media

Script:

-- made by Avia_player nerds!!!!
local RobberyZones = game.Workspace:WaitForChild("Robbery_Zones")
local Assets = game.ReplicatedStorage.RobberyV2.Assets
local RM = require(game.ReplicatedStorage.RobberyV2.Settings_Robbery)
local RUNSER = game:GetService("RunService")

local WhitelistedTeam = "Citizens" -- name of the team that can rob stuff.
local RobberyType = "Large"
local CooldownTime = RM.CooldownTime[RobberyType]

local Timer = RM.RobbingTime

local PlayersInZone = {}

local OnGoingRobbery = false
local Robbable = true
local BeginRobberyUIGive = false
local TimerHasBegan = false

local RobberyZone = script.Parent

local Is_Drillable_Robbery = true -- if you need to drill a door.

local function GivePlayerUI(rpn)
	coroutine.resume(coroutine.create(function()
		local RobbingPlr = game.Players:WaitForChild(rpn)
		local ClonedRobbingUI = Assets.RobbingUI:Clone()
		ClonedRobbingUI.Parent = RobbingPlr.PlayerGui
		
		ClonedRobbingUI.Timer.Text = "REMAINING SECONDS UNTILL SUCCESS: "..Timer.."s"
		
		while Timer ~= 0 and wait(1) do
			print("e")
			ClonedRobbingUI.Timer.Text = "REMAINING SECONDS UNTILL SUCCESS: "..Timer.."s"
		end
	end))
end

local function OnCooldown()
	coroutine.resume(coroutine.create(function()
		TimerHasBegan = false
		Robbable = false
		OnGoingRobbery = false
		
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.PlayerGui:FindFirstChild("RobbingUI") then
				v.PlayerGui:FindFirstChild("RobbingUI"):Destroy()
			end
		end
		
		for i,v in pairs(PlayersInZone) do
			table.remove(PlayersInZone,i)
		end
		
		task.wait(CooldownTime)
		Robbable = true
	end))
end

local function OnRobbery(Target)
	if Robbable == false or OnGoingRobbery == true then return end
	
	local function TheFunctionality()
		coroutine.resume(coroutine.create(function()
			print("Robbery Started")
			Robbable = false
			for i,RobbingPlr in pairs(PlayersInZone) do
				print(RobbingPlr)

				GivePlayerUI(RobbingPlr)
				
				coroutine.resume(coroutine.create(function()
					while Timer ~= 0 and task.wait(1) and OnGoingRobbery == true do
						
						for i,v in pairs(PlayersInZone) do
							local Target = game.Players:WaitForChild(v)
							
							if (script.Parent.Position - Target.Character:WaitForChild("HumanoidRootPart").Position).Magnitude >= 30 then
								print("Gone")
								table.remove(PlayersInZone,table.find(PlayersInZone,Target.Name))
								
								Target.PlayerGui:FindFirstChild("RobbingUI"):Destroy()
								
								
								if #PlayersInZone == 0 and OnGoingRobbery == true then
									OnCooldown()
								end
							end
						end
					end
				end))
				
				coroutine.resume(coroutine.create(function()
					if Timer <= 1 then
						Timer = 0
						
					end
				end))
				
				if TimerHasBegan == true then return else TimerHasBegan = true end
				coroutine.resume(coroutine.create(function()
					while Timer ~= 0 and task.wait(1) and OnGoingRobbery == true do
						Timer -= 1
					end
				end))
			end
		end))
	end
	
	local function GiveUIandBegin()
		if BeginRobberyUIGive == false then
			OnGoingRobbery = true
			local ClonedUI = Assets.BeginRobbingUI:Clone()
			ClonedUI.Parent = Target.PlayerGui
			
			Target.Character.Humanoid.WalkSpeed = 0
			
			coroutine.resume(coroutine.create(function()
				while OnGoingRobbery ~= false and wait() and Target.PlayerGui:FindFirstChild("BeginRobbingUI") do
					local PlayersInZoneCount =  #PlayersInZone

					ClonedUI.MainFrame.PlayersRobbingCount.Text = PlayersInZoneCount
				end
			end))
			
			ClonedUI.MainFrame.Cancel.Button.MouseButton1Click:Connect(function()
				print("Aw, someone canceled the robbery.")
				for i,v in pairs(PlayersInZone) do
					table.remove(PlayersInZone,i)
				end
				Target.Character.Humanoid.WalkSpeed = 16
				ClonedUI:Destroy()
				OnCooldown()
			end)
			
			ClonedUI.MainFrame.Button.MouseButton1Click:Connect(function()
				Target.Character.Humanoid.WalkSpeed = 16
				ClonedUI:Destroy()
				TheFunctionality()
			end)
		end
	end
	
	GiveUIandBegin()
end

local function WhenInZone(Target)
	if table.find(PlayersInZone,Target.Name) ~= nil then print(Target.Name) return end
	if Robbable == true then
		if table.find(PlayersInZone,Target.Name) ~= nil then 
			print("Bruh 2")
			return 
		else
			if Target.Team.Name == "Citizens" then
				table.insert(PlayersInZone,Target.Name)
				OnRobbery(Target)
			else

			end
		end
		wait()
	else
		
	end
end

coroutine.resume(coroutine.create(function()
	while true and task.wait(1) do
		for i,v in pairs(PlayersInZone) do
			print(v)
		end
	end
end))

coroutine.resume(coroutine.create(function()
	while task.wait() do

		local region = Region3.new(RobberyZone.Position - (RobberyZone.Size/2),RobberyZone.Position + (RobberyZone.Size/2))
		local parts = game.Workspace:FindPartsInRegion3(region)
		for _, part in pairs(parts) do
			if part.Parent:FindFirstChild("Humanoid") then
				local Target = game.Players:GetPlayerFromCharacter(part.Parent)
				
				WhenInZone(Target)
				break
			else
			end
		end
	end
end))
	
	

local Door = script.Parent:WaitForChild("ValutDoor")
local DoorProxy = Door.ProximityPrompt

local function DoorDrilling(plr)
	local function Functionality()
		if plr.Backpack:FindFirstChild("Drill") or plr.Character:FindFirstChild("Drill") then else return end
		if Robbable == true then else print("NOT ROBBABLE NERD") return end
		local ClonedDrillingUI = Assets.Drilling_Task:Clone()
		ClonedDrillingUI.Parent = plr.PlayerGui
		DoorProxy.Enabled = false
		Is_Drillable_Robbery = false
		
		local function DrillAnimAndVisual()
			local TS = game:GetService("TweenService")
			local Drill = DoorProxy.Parent.Drill
			local DrillPosFinish = DoorProxy.Parent.DrillPosFinish
			
			TS:Create(Drill,TweenInfo.new())
		end
		
		
		
		Assets.Parent.Remotes.BeginDrillingTask:FireClient(plr,script)
		
		
		Assets.Parent.Remotes.EndDrillingTask.OnServerEvent:Connect(function(plr, S)
			if S == script then
				coroutine.resume(coroutine.create(function()
					script.Parent:WaitForChild("ValutDoor").CanCollide = false
					task.wait(300) --- if some weirdo just drills the door and leaves it open.
					script.Parent:WaitForChild("ValutDoor").CanCollide = true
				end))
			end
		end)
		
		
		plr.Character.Humanoid.Running:Connect(function(speed)
			if 1 >= speed then
				if Robbable ~= true then return end
				if ClonedDrillingUI then
					if ClonedDrillingUI.Parent == plr.PlayerGui then
						ClonedDrillingUI:Destroy()
						DoorProxy.Enabled = true
						Is_Drillable_Robbery = true
					end
				end
			end
		end)
	end
	
	if plr.Team.Name == WhitelistedTeam then
		Functionality()
	end
end


DoorProxy.Triggered:Connect(function(plr)
	if Is_Drillable_Robbery == true then
		DoorDrilling(plr)
	end
end)

Maybe try using zoneplus? they have simple api and full documentation

Will try that, thank you.
--------------

Region3 is deprecated, just use workspace:GetPartBoundsInBox(cframe, size, OverlapParams)

Also, this is how you create the parameter OverlapParams:

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include -- this is the updated version of "Whitelist"
params.FilterDescendantsInstances = {} -- Just add an instance, for example a folder, self explanatory

And then there are some optional parameters that you can add:

That shouldn’t give any issues, but if it does just let me know.

2 Likes

Okay, let me try that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.