Why do the part destroy when a player touches them?

Sorry for asking so many questions, but why do these parts that are created destroy when a player touches them rather then when a tool touches them?

function CoalOre()
	local Ore = Instance.new("Part",workspace)
	Ore.Anchored = true
	Ore.CFrame = CFrame.new(math.random(-50, 50), 1, math.random(-50, 50))
	Ore.Shape = Enum.PartType.Ball
	Ore.TopSurface = Enum.SurfaceType.Smooth
	Ore.BottomSurface= Enum.SurfaceType.Smooth
	Ore.Size = Vector3.new(3, 3, 3)
	Ore.BrickColor = BrickColor.new("Black")
	Ore.Material= Enum.Material.Pebble
	Ore.Touched:connect(function(p)
		if p.Parent.Name == "Coal Pickaxe" or "Handle" then
			Ore:Destroy()
		end
	end)
end
while wait(math.random(2,5)) do
	CoalOre()
end

EDIT:
It works fine for the other one

function CopperOres()
	local CopperOre = Instance.new("Part",workspace)
	CopperOre.Anchored = true
	CopperOre.CFrame = CFrame.new(math.random(-50, -30), 1, math.random(-50, -3))
	CopperOre.Shape = Enum.PartType.Ball
	CopperOre.TopSurface = Enum.SurfaceType.Smooth
	CopperOre.BottomSurface= Enum.SurfaceType.Smooth
	CopperOre.Size = Vector3.new(3, 3, 3)
	CopperOre.BrickColor = BrickColor.new("Copper")
	CopperOre.Material= Enum.Material.Pebble
	CopperOre.Touched:connect(function(p)
		if p.Parent.Parent.Name == "Copper Pickaxe" then
			CopperOre:Destroy()
			local humanoid = (p:FindFirstAncestorOfClass("Model") or p.Parent):FindFirstChild("Humanoid")
			local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
			local leaderstats = player:FindFirstChild("leaderstats")
			local Coins = leaderstats:FindFirstChild("Gold")
			if Coins then Coins.Value = Coins.Value + 10
		  end
		end
	end)
end
while wait(math.random(12,15)) do
	CopperOres()
end

You got this bit wrong, you need to put

if p.Parent.Name == "Coal Pickaxe" or p.Parent.Name == "Handle" then
3 Likes

Also, is this happening for you too? When I play test my game I die when the loading screen shows up

When you use an if statement, or means “if either of the conditions are true”. When you have a value by itself, it evaluates to true and when you have nil it evaluates to false (so that you can do if value then to see if value exists). In essence, your if statement would evaluate to (assuming p.Parent.Name = "Hello"):

if false or true then ... end

This will always run regardless because you have true as an alternate condition.

1 Like

maybe it destroys one of your limbs

1 Like