Table.find with GetParts() not working

Hi!

I was tryign to make a CanTouch system, but the table.find isn’t working.

		if Placing_FI == 1 then
			Part.Position = Vector3.new(MathRound(Mouse.hit.p.x), BuildPlate.Position.Y + (BuildPlate.Size.Y / 2) + (Part.Size.Y / 2), MathRound(Mouse.hit.p.z))
			Part.Transparency = 0.4
			local results = GetTouchingParts(BuildPlate)
			Print(results)
			if table.find(results, "PlacingModel") then CanPlace = true Print("Can Place!") else CanPlace = false Print("CanPlace is false!")return end
			if not CanPlace then Part.Color = Color3.fromRGB(255, 69, 72) Print("Cant place!") return end

Function:

local function GetTouchingParts(part)
	Print(workspace:GetPartsInPart(part))
	return workspace:GetPartsInPart(part)
end

I don’t know if I used GetPartsInPart correctly.
output:


Thanks for any help!

Also, ignore the capital p in Print(), i have a special function for printing, with a debug variable.

The reason this didn’t work is because GetPartsInPart() returns an array of part instances through which you attempt to find an entry within the array from its value by specifying a string value corresponding to the part name you are checking for, as the values are stored as instances this will never match, instead I’ve opted to instead traverse over the items in the array and check if any of the instances are named “PlacingModel” by accessing the value of their “Name” properties individually.

if Placing_FI == 1 then
	Part.Position = Vector3.new(MathRound(Mouse.hit.p.x), BuildPlate.Position.Y + (BuildPlate.Size.Y / 2) + (Part.Size.Y / 2), MathRound(Mouse.hit.p.z))
	Part.Transparency = 0.4
	local results = GetTouchingParts(BuildPlate)
	Print(results)
	for _, part in pairs(results) do
		if part.Name == "PlacingModel" then
			CanPlace = true
			Print("Can Place!")
		else
			CanPlace = false
			Print("CanPlace is false!")
			return
		end
		if not CanPlace then
			Part.Color = Color3.fromRGB(255, 69, 72)
			Print("Cant place!")
			return
		end
	end
1 Like