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
It’s own parts
The spawn
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.
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”.
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.