Thing to note, PrimaryPart.CanCollide is set to false. It has to be set to false as I’m using it in a placement system and if it’s set to true it collides with the player which is just frustrating.
I’ve read the wiki already, and it states that this can be done if there’s a TouchInterest involved, however, I’m unsure where this should be put? Inside the model? Inside the PrimaryPart? Inside every part?
I have a weird solution, it’s what Restaurant Tycoon does. Every time an object it placed, the ‘base’ part is teleported 100 studs above the map, set cancollide = true, and checks for collisions with other parts. Basically there are loads of hitboxes exactly 100 studs above where every item was placed.
I don’t know what other games do, but this seems to work fine for me.
Using that tho, how can I get it diffirentiate between the parts inside its model or other parts.
for _, v in pairs(getTouchingParts(itemClone.PrimaryPart)) do
if not v:IsDescendantOf(itemClone) then
itemClone.PrimaryPart.Transparency = 0.75
itemClone.PrimaryPart.Transparency = 1
Obviously when it collides with a different models parts that transparency would change to 0.75. However, as the PrimaryPart is technically continously colliding with parts inside it’s own model, means it will always has a transparency of 1. What are work arounds to this
Connecting a function to part.Touched creates the TouchInterest, which will let you call part:GetTouchingParts() without having to say part.CanCollide = true.
aka, this code right here:
will create a TouchInterest, which you can then use to call part:GetTouchingParts().
According to the page referring to part:GetTouchingParts(), the function will only return any parts that are “physically interacting with this part,” which suggests that it will only return parts with CanCollide = true, which means it ignores other parts that are CanCollide = false while also having a TouchInterest.
Therefore, what you can do is make your entire model (or just some parts) CanCollide = false, connect empty functions to their .Touched events if necessary, and use your transparency function right there to differentiate between what is and is not colliding with the part.
I hope that helps. I’m never entirely sure if it does…
That’s essentially the same thing addisonshiu linked, but apparently that doesn’t solve OP’s problem. I don’t really understand the situation myself, I’m still having a look at it.
That being said; @OP, I don’t think you can do that (differentiating between descendants or ancestry parts directly from the table). All you can do is use GetTouchingParts to return an array of parts that are, of course, touching the BasePart which you called the method on. Ancestry isn’t accounted for.