How to ignore parts of the player

I’m trying to basically have it so if the model is intersecting another model, its hitbox would turn visible, if not it’d be invisible. It should be ignoring if it’s touching

  1. It’s own parts
  2. The spawn
  3. The players character
for _, v in pairs(getTouchingParts(itemClone.Hitbox)) do
	if not v:IsDescendantOf(itemClone) or v.Name == 'Spawn' or v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character) then
	    itemClone.Hitbox.Transparency = 0.5	
	    break			
    end
    itemClone.Hitbox.Transparency = 1
end

However, I managed to get it to work with the first 2, but when I try to have it ignore the players character it just always says something is intersecting it. I’ve tried putting a not infront of the v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character) but the model still has its transparency change.

2 Likes

The not here is only applying to the first part of the if statement, try:

if not (v:IsDescendantOf(itemClone) or v.Name == 'Spawn' or v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character)) then
5 Likes

I already tried that and it just meant I couldnt place it anywhere

With the not

if not (v:IsDescendantOf(itemClone) or v.Name == 'Spawn' or not v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character)) then


Without the not

if not (v:IsDescendantOf(itemClone) or v.Name == 'Spawn' or v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character)) then


1 Like

You are trying to check if something does not have certain properties. The thing is, the “not” only applies to the “v:IsDescendantOf(itemClone)”, not the whole statement. Try this:

if not (v:IsDescendantOf(itemClone) or v.Name == 'Spawn' or v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character)) then

This will apply the “or”'s first and then apply the “not”.

This still does this



The problem has to do with the character portion of the if statement, not the itemClone descendants or spawn

if not v:IsDescendantOf(itemClone) or v.Name == ‘Spawn’ or v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character) then

The above if statement doesn’t run if v is a child of itemClone, and ALWAYS runs if v is not a child of itemClone

Ok, so how would I fix it???/

To clarify; you want the hit box to turn to 0.5 transparency if v is not the object itself, is not a spawn, and is not a character?

This seems confusing to me because your if statement is saying if the object is a spawn or is a character then the hit box becomes 0.5 transparency.

I would go about this by removing the parts from the table that you would like to ignore, then checking if the amount of parts in the table is >=1(in which case the hitbox would be visible)

Yes, your implementation of the code is confusing. I honestly feel like you’re not using “not” correctly because if the v.Name is Spawn, it will fire, but you don’t want it to. I recommend trying to test for one at a time so you can see which gives you trouble. Basically like this:

-- Test 1; run game, see if it works
if not v:IsDescendantOf(itemClone) then
	    itemClone.Hitbox.Transparency = 0.5	
	    break			
end
-- Test 2; replace above, run game, see if it works
if v.Name == 'Spawn' then
	    itemClone.Hitbox.Transparency = 0.5	
	    break			
end
-- Test 3; replace above, run game, see if it works
if v:IsDescendantOf(players:FindFirstChild(playersPlot.Name).Character) then
	    itemClone.Hitbox.Transparency = 0.5	
	    break			
end

Basically see which one is not picking up. If they all work like this, try experimenting when putting them together. I honestly think that the problem is in one of these testing statements, not the not.

I hope you find your solution!