Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Nothing is happening when I run this landmine code, what did I do wrong?

Asked by 8 years ago
Edited 8 years ago

What im trying to do is have multiple mines explode when you touch them.

01function Touch(part)
02    while true do
03        touch = 1
04        wait(1)
05    end
06end
07 
08function 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
View all 32 lines...
0
Any errors? Is "Mine" an Model or what? antonio6643 426 — 8y
0
Also do note that your Mine function is override by the "Mine" variable and I don't see your Mine function called when the part is touched. antonio6643 426 — 8y
0
Mine is a part i have SmugNyan 24 — 8y
0
The code works, but it will instantly explode upon playing because it's not looking to make sure that a person is touching it. block01352 57 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
01while true do
02 
03children = game.Workspace:GetChildren()
04 
05for _, 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")
View all 27 lines...

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.

0
oh ok thank you. SmugNyan 24 — 8y
0
I tested it and it worked perfectly but I already knew how to do that. What I wanted was if it would work on multipile "Mine"s. Sorry, I should've made it more clear in the desc. SmugNyan 24 — 8y
0
Updated my code block. This should work for multiple Mines now. block01352 57 — 8y
0
I think 'children' should be defined inside the while loop. Since his game is probably dynamic, after a bit of time the 'children' table could become outdated.. Goulstem 8144 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question