What im trying to do is have multiple mines explode when you touch them.
function Touch(part) while true do touch = 1 wait(1) end end function Mine(part) if part.BrickColor == BrickColor.Black()then explosion = Instance.new("Explosion") explosion.Position = part.Position explosion.Parent = game.Workspace part.BrickColor = BrickColor.White() else if touch == 1 then part.BrickColor = BrickColor.Black() end end end children = game.Workspace:GetChildren() while true do for _, child in pairs(children) do if child.Name == "Mine" then Mine(child) end end wait(1) end Mine = game.Workspace.Mine Mine.Touched:connect(Touch)
while true do children = game.Workspace:GetChildren() for _, child in pairs(children) do if child.Name == "Mine" then child.Touched:Connect(function(hit, part) part = child if hit.Parent:FindFirstChild("Humanoid") then part.BrickColor = BrickColor.Black() if part.BrickColor == BrickColor.Black()then local explosion = Instance.new("Explosion") explosion.Position = part.Position explosion.Parent = game.Workspace part.BrickColor = BrickColor.White() wait(3) part.BrickColor = BrickColor.Black() end end end) end end wait(1) end
Your initial code is not set up for detecting a player. When you want to detect that a player is touching your landmine, you generally need to find if the part that touched the mine contains a Humanoid, which all players have.
I always find it easier to place multiple items I want a function on in a folder and script it as
Local folder = workspace:WaitForChild("name of the folder") Local parts = folder:GetChildren()
For _, object in pairs(parts) do --// code here End
that works for me. I'd put that in code block but my phone don't work like that lol