game.Workspace:GetPartBoundsInBox() always returning nil

This is my code:

´´´lua

bind = RunService.RenderStepped:Connect(function()
	ghost.Position = mouse.Hit.Position
	local plot = localPlayer:WaitForChild("Plot").Value
	
	
	local hitbox = game.Workspace:GetPartBoundsInBox(plot.CFrame,plot.Size)
	if table.find(hitbox,ghost) then
		ghost.Color = Color3.new(0,1,0)
	else
		ghost.Color	= Color3.new(1,0,0)
	end
	
end)

´´´

ghost is just a part i am moving with my mouse and plot gets the plot that is assigned to the player, it’s a part that is invisible. The part i’m placing is always red meaning table.find returned nil meaning ghost is not inside the plot, event though i’m clearly placing it inside the plot. Is there something wrong with my code?

Edit: Collision and CanQuery are set to false on the plot but the roblox page about GetPartBoundInBox() says that doesnt matter (I havent specified OverlapParams)

that’s not how it works. You do it with a region THEN you do the parts and stuff. Like this

bind = RunService.RenderStepped:Connect(function()
	ghost.Position = mouse.Hit.Position
	local plot = localPlayer:WaitForChild("Plot").Value
	
	local region = Region3.new(plot.Position - plot.Size / 2, plot.Position + plot.Size / 2)
	

	local hitbox = game.Workspace:GetPartBoundsInBox(region.CFrame,region.Size)
	if table.find(hitbox,ghost) then
		ghost.Color = Color3.new(0,1,0)
	else
		ghost.Color	= Color3.new(1,0,0)
	end

end)
1 Like

Thanks for replying!
The part still remains red though? So something else must also be not working

I know nothing about your code/game.

It seems to be an issue unrelated to the GetPartsBoundsInBox()

My code should solve the issue with GetPartsBoundInBow(). I recommend you mark my post as solution, then make a new topic asking for help with the issue you’re having now.

1 Like

Ok, i marked your first post as solution. I’ll check my code for any errors. Thanks!

1 Like