GetPartBoundsInBox trouble

  1. Have a code,which basically checks,if player is in the zone,using GetPartBoundsInBox

  2. Worked just fine,until last update,wondering if its just a coincidence,or it really did break something,now it keeps having issues,constantly couting that player left the zone and rentered non-stop,even if player dont move out of the zone

  3. What strange is that i have other code,having exact same structure,yet it dont have this issue,and finds player normally
    tried changing part directories,didnt work,
    anchor and collide change didnt affect this either

-- while 1 do task.wait(0.25)
		---------------------------------------------------------
			local fndPlrInZn=false 
			---------------------------------------------------------

			
			---------------------------------------------------------
			--Setups bounding box
			---------------------------------------------------------
			local pdmTrgPrtSize = ovrlpTrgPrt.Size
			local pdmTrgCFrame = ovrlpTrgPrt:GetPivot()
			-------------------------------------------------------
			local overlapParams = OverlapParams.new()
			overlapParams.FilterType = Enum.RaycastFilterType.Exclude
			overlapParams.FilterDescendantsInstances = {ovrlpTrgPrt}
			local overlappingParts = workspace:GetPartBoundsInBox(pdmTrgCFrame, pdmTrgPrtSize, overlapParams)
			-------------------------------------------------------
			for _,obj in pairs(overlappingParts)do 
			---------------------------------------------------------


				---------------------------------------------------------
				--Tries to find plr
				---------------------------------------------------------
				local character = obj:FindFirstAncestorWhichIsA("Model")
				---------------------------------------------------------
				if character and game.Players:GetPlayerFromCharacter(character) then
				---------------------------------------------------------
					local fndPlr = game.Players:GetPlayerFromCharacter(character)
					---------------------------------------------------------
					
					
					---------------------------------------------------------
					--If finds player,logic happens
					---------------------------------------------------------
					local plrNm=plr.Name
					if fndPlr.Name == plrNm then fndPlrInZn=true
					---------------------------------------------------------
						if not plrIWasInTrgZn then print("PlrEntredTrgZn")
						---------------------------------------------------------
							local oldFrm=invClnPrntGui:FindFirstChildWhichIsA("Frame") if oldFrm then oldFrm:Destroy()end
							---------------------------------------------------------
							plrIWasInTrgZn=true
							---------------------------------------------------------
							SetupInventory(ovrlpTrgPrt)
							task.wait(0.15)
							---------------------------------------------------------
							twnMdl.TweenGui("open", guiNm)
							---------------------------------------------------------
							CheckBuildingBeingPresent(ovrlpTrgPrt)
							---------------------------------------------------------
						---------------------------------------------------------
						end
					---------------------------------------------------------
					end
					---------------------------------------------------------
				---------------------------------------------------------
				end
			---------------------------------------------------------
			end
			---------------------------------------------------------
			if plrIWasInTrgZn and not fndPlrInZn then print("PlrLeftZone")
			---------------------------------------------------------
				twnMdl.TweenGui("close", guiNm)
				twnMdl.TweenGui("close", "InvCloneGui")
			--local oldFrm=invClnPrntGui:FindFirstChildWhichIsA("Frame") if oldFrm then oldFrm.Parent=plr.PlayerGui.TempGui end  NOLAGSPIKE
				local oldFrm=invClnPrntGui:FindFirstChildWhichIsA("Frame") if oldFrm then oldFrm:Destroy()end
				plrIWasInTrgZn=false 	
			end
			---------------------------------------------------------
		end	

So again,did work until recent updates,now issue is it has constant flags issues,where overlap check says player left,even when player stays still

This code makes my eyes hurt.
There’s no way code could be “readable” (it will be the opposite) if you spam dashes everywhere.
Vro :v: :broken_heart: :wilted_flower:

  • Also avoid using ipairs/pairs because generic iteration is better.

  • Cache hot path like: local TweenGui = twnMdl.TweenGui

  • Just use a touch event with debounce. Why make life hard for no reason?

  • You’re overengineering a simple zone check and hurting performance for no reason.

3 Likes

1)thanks for saying about everything but the problem solution
2)it dont hurt perfomance lol,its a simple boundbox check
3)i use this “spam” code style for a while,made my life much easier for 800+ scripts

i know touched will be easier to use,what hurts is i dont get the problem reason,
this exact code works fine for exact same scenarios, i wondered if anyone knew the reason for boundbox check to fail find static player in this case
:hugs: thanks for spam brother


br thk h shkspr :wilted_flower: :broken_heart:


pairs is used for dictionaries, GetPartBoundsInBox returns an array
although nowadays the luau compiler spoonfeeds you by deciding the best one

also i ltierally have no clue what any of these variables are can you please write like a normal person
plrIWasInTrgZn :broken_heart:

1 Like

Uh, it does not decide for you in case of pairs.
It decides in generic iteration only, aka FORGPREP, so for i,v in {} do end
Pairs otherwise is a legit wrapper for next() :skull:
The compiler straight up unwraps it into FORGPREP_NEXT

Nah but naming mockery is epic ngl :mending_heart: :sunflower:

i cnt rly rd ts bt thrs olny 1 sctn of th code tht dsabls plrIWasInTrgZn, try lokng arnd thre

(Also get the SimpleComplete plugin, trust me)

3 Likes

I recommend you use ZonePlus to check if players are in certain zones, it makes life easier

I’m confused. what’s the actual issue?
How does the console look? You gotta give more information. I would also recommend reading up on code formatting and such.