What im trying to do is have multiple mines explode when you touch them.
01 | function Touch(part) |
02 | while true do |
03 | touch = 1 |
04 | wait( 1 ) |
05 | end |
06 | end |
07 |
08 | function Mine(part) |
09 | if part.BrickColor = = BrickColor.Black() then |
10 | explosion = Instance.new( "Explosion" ) |
11 | explosion.Position = part.Position |
12 | explosion.Parent = game.Workspace |
13 | part.BrickColor = BrickColor.White() |
14 | else |
15 | if touch = = 1 then |
01 | while true do |
02 |
03 | children = game.Workspace:GetChildren() |
04 |
05 | for _, child in pairs (children) do |
06 |
07 | if child.Name = = "Mine" then |
08 | child.Touched:Connect( function (hit, part) |
09 | part = child |
10 |
11 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
12 | part.BrickColor = BrickColor.Black() |
13 |
14 | if part.BrickColor = = BrickColor.Black() then |
15 | local explosion = Instance.new( "Explosion" ) |
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