I have a bunch of tiles located near each other. I want to know if tile is occupied or not. To do that, I tried using :GetPartBoundsInBox, but no matter what I do, I can not get the list of parts in bound box, and it always returns empty array. Am I doing something wrong?
Script:
local tile = script.Parent.Parent.Base
script.Parent.MouseClick:Connect(function()
local OverlapParams = OverlapParams.new()
OverlapParams.FilterType = Enum.RaycastFilterType.Include
OverlapParams.FilterDescendantsInstances = {workspace.Tile}
OverlapParams.MaxParts = 4
OverlapParams.CollisionGroup = "Default"
local boundBox = workspace:GetPartBoundsInBox(CFrame.new(tile.Position.X, tile.Position.Y + 4.5, tile.Position.Z), Vector3.new(8, 8, 8), OverlapParams)
if boundBox then
print(boundBox)
end
end)```
When you hover over a part in studio, do you see that blue box around it? That is it’s bounds. What the function does is just get a segment of your choice, then checks to see if there are any bounds inside of it. Then puts all the parts into a table. Great for stuff like hitboxes if you don’t want to use .Touched!
Yeah, that is indeed great. I just don’t understand why my script specifically does not work. It creates like a 8 by 8 by 8 studs box above the tile, and gets the parts inside that box, but that is just in theory. Do I have a wrong idea of how it works?
You might need to put it inside a loop, but I do notice that it only checks if the click detector is clicked. It could be due to the fact that in line 5, you used Enum.RaycastFIlterType.Include. I’m not too good with enums, but shouldn’t you use something else instead? I don’t think :GetPartBoundsInBox() uses raycasts.
Nevermind, I just did some reasearch myself and found out it does use Enum.RaycastFilterType. Are you using a Server Script or a Local Script for the click detector? Because you can’t use Local Scripts on a click detector.
It doesn’t matter what scripts you use, it’s just that you should use Exclude instead of Include for the raycast params. Streaming enabled may cause problems if you run it on a client.