First, I know that there are other topic(s) about this but the solution isn’t the same.
I’ve made a system where Ores spawn But the problem is that they can spawn in each other, Firstly I tried touched events they didn’t work (Only prints when the Player touches it)
For the Second try I tried GetTouchingParts() What happened? Well it’s acting really weird it just detects if the main part the one touching it self and just destroys on spawn
Code
local IsCollidingResults = game.Workspace:GetPartBoundsInBox(GoldOreClone.CFrame, Vector3.new(4,4,4,4),OverlapParams.new())
for _, Item in ipairs(IsCollidingResults) do
print(Item) --Printing the same Item it self
task.wait(1)
if Item.Name == "GoldOre" or "EnchantedGoldOre" then
GoldOreClone:Destroy() -- destroying it self even though it didn't touch another gold.
return
end
end
And No, It’s not working when they spawn at the same time it despawns after a second because "“it touched it self” which it shouldn’t be touching it self the size is 4,4,4,4 of the rock.
So from what I’m understanding the ore is meant to destroy another if they spawn at the same position correct? What’s going on is that an ore is “touching” itself and self-destructing? If that’s the case, just include an if statement to verify if the ore isn’t touching a part of himself. If there are multiple parts contained within the main hitbox, those will count as “touched”.
It still removes it without even touching it. and Yes that’s the case.
local IsCollidingResults = game.Workspace:GetPartBoundsInBox(EnchantedGoldOreClone.CFrame, Vector3.new(4,4,4,4), OverlapParams.new())
for _, Item in ipairs(IsCollidingResults) do
if Item.Name == "EnchantedGoldOre" or Item.Name == "GoldOre" and Item ~= EnchantedGoldOreClone then
EnchantedGoldOreClone:Destroy()
return
end
end
Oh, upon reading your code I believe I have spotted the problem.
This is simply a logic problem, let’s break down your if statement.
First, this condition is evaluated
if Item.Name == "EnchantedGoldOre"
And then, because of the way or behaves logically, it checks for this entire condition on its own.
Item.Name == "GoldOre" and Item ~= EnchantedGoldOreClone
Which means that if the Item’s name is “EnchantedGoldOre”, which I believe it would be since that’s what you’re trying to create, it won’t even check the Item.Name == "GoldOre" and Item ~= EnchantedGoldOreClone because one of the sides is already true.
To fix that, rewrite your if statement as:
if (Item.Name == "EnchantedGoldOre" or Item.Name == "GoldOre") and Item ~= EnchantedGoldOreClone then
Parenthesis really do make a lot of difference to the final result of your code, always be mindful of this when using the or operator, as it can get very tricky.
1 Like