How could i use getbounds?

Hi, So today i learned how to use GetPartBoundsInBox, But i dont know how to check for what parts its touching?

Heres the script:

local RunService = game:GetService("RunService")

local Part = script.Parent

RunService.Heartbeat:Connect(function()
	local filiter = OverlapParams.new()

	filiter.FilterDescendantsInstances = {Part}
	filiter.FilterType = Enum.RaycastFilterType.Exclude

	local cf, size = Part.CFrame, Part.Size
	return workspace:GetPartBoundsInBox(cf, size, filiter)
	
end)

You are returning data in an event, which you probably shouldn’t do, just make the bounding box a variable and just print the contents:

local RunService = game:GetService("RunService")

local Part = script.Parent

RunService.Heartbeat:Connect(function()
	local filiter = OverlapParams.new()

	filiter.FilterDescendantsInstances = {Part}
	filiter.FilterType = Enum.RaycastFilterType.Exclude

	local cf, size = Part.CFrame, Part.Size
	local BoundBox = workspace:GetPartBoundsInBox(cf, size, filiter)
	
	print(BoundBox)
	
end)
2 Likes

What are you trying to do?? Why are you returning from a heartbeat??

Just:

local parts = workspace:GetPartBoundsInBox(...)
for _, part in ipairs(parts) do
--access here
end

Edit: you can also just use BasePart:GetTouchingParts() because it seems like you are just setting the cframe and size to the ones of a part.

2 Likes

Well i am trying to check if a trees hitbox is touching the part, And lets just say it would print out “hit tree” or something

Didn’t me and @scavengingbot give you ideas and fixes you can implement? Just adjust your code to your desired behaviour.

1 Like

Yeah and i used them and figured it out, So thank you both

2 Likes