I want to know how know if there is 2 of the same part. I am making a little puzzle that the player needs to solve by pushing around the ball. My code:
local toggle = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not toggle then
toggle = true
script.Parent.BrickColor = BrickColor.new("Really black")
script.Parent.Material = ("Plastic")
local ball = Instance.new("Part",game.Workspace)
Instance.new("Part",game.Workspace)
ball.Shape = Enum.PartType.Ball
ball.Position = Vector3.new(-24, 110, 0)
ball.BrickColor = BrickColor.new("Institutional white")
ball.Material = ("SmoothPlastic")
ball.Size = Vector3.new(10, 10, 10)
ball.Name = ("Ball")
game.Workspace.Ball:Destroy()
wait(5)
script.Parent.BrickColor = BrickColor.new("Lime green")
script.Parent.Material = ("Neon")
toggle = false
end
end
end)
I want to make it so if there is 2 balls then the script will delete one ball. But I don't know how to count how many balls there is and there is one problem were if there is no balls like if it falls off the map and I respawn it will just delete it self. How do I fix this?

2 comments
the balls do not go with a specific player i am making a little puzzle that the player needs to solve by pushing around the ball
Then just delete the ball before spawning the next one. Search for it in the workspace with the index to variable for loop (EX: 'for i,v in pairs(workspace:GetChildren()')