:GetTouchingParts() returning an empty table

local partsIn = tool.Part:GetTouchingParts()
print(partsIn)

partsIn is printing {}, even though I have the hitbox inside a part. Any idea why?

(Yes the hitbox is welded to the actual tool)

2 Likes

Also, I don’t know if it matters, but it is in an Activated function.

1 Like

Does the hitbox have CanCollide and CanTouch on?

You should use GetPartsinPart instead, TouchingParts works really funny and is deprecated.

GetPartsInPart does not exist.

1 Like

No, but I fixed the initial issue by adding a Touched event to create a touch interest. Now, using table.find() isn’t returning true even though it is clearly in the table.

if table.find(partsIn,"Rice")...```
1 Like

GetPartsInPart does exist, it is a method of workspace, you don’t need to use a hacky method like adding touch interest using GetPartsInPart

2 Likes

Oh, I see, thankyou for the insight.

2 Likes

Show me your script

zsdzs

1 Like
tool.Activated:Connect(function()
	if debounce then return end
	debounce = true
	local playAnim = char.Humanoid.Animator:LoadAnimation(animation)
	playAnim:Play()
	
	local partsIn = tool.Part:GetTouchingParts()
	if table.find(partsIn,"Rice") and farmDebounce == false then
		farmDebounce = true
		
		for i, v in pairs(partsIn) do
			if v.Name == "Rice" then
				game.ReplicatedStorage.CollectRice:FireServer(1, v)
			end
		end
	end
	
	task.wait(.5)
	debounce = false
	farmDebounce = false
end)

tool.Part.Touched:Connect(function() end)

Doesn’t make it past the table.find() check

1 Like

Did you try to print the table?? Show me the output

1 Like

image

1 Like

You can’t use table.find on dictionaries

What should I use then? sdfsdffs

1 Like

it isn’t a dictionary, it is an array (table)

1 Like

Just do a for loop and check if the value is equal to “Rice”

for index, value in ipairs(partsIn) do
    if value == "Rice" then
         --stuff
    end
end

Can I get the actual object as well (to alter its attribute and stuff)

here is the correction GetTouchingParts returns all the BaseParts that are touching not just the names

Oh, he confused me, because I thought the element was a string

1 Like

So how can I check if a certain part is in the array