if TouchingParts then
for index, touching_part in pairs(TouchingParts) do
print(touching_part)
if touching_part.Parent then
if touching_part.Parent:FindFirstChild("Humanoid")then
break -- stops the loop from analysing the other parts of the Character if it finds one part belonging to a character
elseif touching_part.Parent:IsA("Folder") and touching_part.Parent.Parent.Name == "Nods" then
Mining_Damage_Event:FireServer(touching_part, Pickaxe:GetAttribute("Pickaxe"))
end
end
end
end
What you could possibly do is make it so that you clamp the health of the rock by using math.min(new health,0) . Secondly, after doing the first step you can add it to a table on where all the rocks are broken such as using this:
local BrokenRocks = {}
--After checking if it is rock and decreasing the health
if not table.find(BrokenRocks, rock) then -- allows it to keep going if it is not in the table
rock.Health = -- the new health
if rock.Health <= 0 then table.insert(BrokenRocks,rock) end
end
I fixed it by adding an if statement to check if the touching_part, basically the rock is a Descendant of workspace to see if it still exists in the workspace.
if TouchingParts then
for index, touching_part in pairs(TouchingParts) do
if touching_part:IsDescendantOf(workspace) then --Here's the fix
print(touching_part)
if touching_part.Parent then
if touching_part.Parent:FindFirstChild("Humanoid")then
break -- stops the loop from analysing the other parts of the Character if it finds one part belonging to a character
elseif touching_part.Parent:IsA("Folder") and touching_part.Parent.Parent.Name == "Nods" then
Mining_Damage_Event:FireServer(touching_part, Pickaxe:GetAttribute("Pickaxe"))
end
end
end
end
end
sorry for the messy format of the code, i’ll fix it later. Thank you for the help guys!