Check if part is already at a CFrame

Hi

I have a script that clones a model, then sets the PrimaryPart CFrame, to a random part’s CFrame but there will be multiple models at the same CFrame, how can I fix this?

1 Like

Well either u put bool values into the points or put IntValues into primary part

You could also remove the parts from the table as you visit them, something like:

local partsToVisit = workspace.PartsToVisit:GetChildren()

local function Visit()
    local index = math.random(1, #partsToVisit)
    local removedPart = table.remove(partsToVisit, index)
    return removedPart
end

Visit()
Visit()
Visit()
Visit()
-- ... etc
function FindPart(model)
	local found, part = false, nil
	for i,v in pairs("Location of parts") do
		if v.CFrame == model.PrimaryPart.CFrame then
			found = true
			part = v
		end
	end
	if found then
		print("Found the part".. part.Name .. " !")
	else
		warn("PART NOT FOUND")
	end
end

Try this

You can’t compare CFrames like this. You could use Vector3:FuzzyEq on the positions I guess, but I don’t think comparing positions is the right way anyways.

I don’t use CFrame often but you can compare positions and it will work because it has been set exactly the same as the other part/model