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

Help with in pairs stuff [?]

Asked by 8 years ago
Blocks= {"Emerald","Ruby","Sapphire","Diamond","Coal","Coal","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Di  rt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt"}

function Mako()
for _, Part in pairs(script.Parent:GetChildren()) do
  if script.Parent.Parent.Generate.BrickColor ~= "Really red" then
    local Rocky = game.Lighting:FindFirstChild(Blocks[math.random(1,#Blocks)])
    local Mine = Rocky:Clone()
        Mine.Position = script.Parent.Part.Position
        Mine.Parent = script.Parent.Parent.Field
         else
        print("Cooling Down, Please wait")
          end
        end
end

script.Parent.Parent.Generate.ClickDetector.MouseClick:connect(Mako)

this script is supposed to do this function to all parts named part in script.Parent instead it just takes a bunch of clones from lighting and puts them into the position of one brick

no errors cuz the if statement

1 answer

Log in to vote
0
Answered by 8 years ago

Yes, there is a way to make all of this one script.

First, Let me explain how thing should be set up for it to function, at least how I will make the code function. Now I will assume 'Generate' is the part that has the copies, all of which are named Generate. So, what we will do is make all of the Generate modeled, I'll call the model Clickers you may change this... and really anything else you want, it is yours after all.

The first thing we do is keep the table you have already prepared. Then we want to use a Generic Loop which will cycle threw each of the contents of the Model, setting up a MouseClick event to each.

Blocks =    {"Emerald","Ruby","Sapphire","Diamond","Coal","Coal","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Di  rt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt"}

for _, Generate in pairs(game.Workspace.Clickers:GetChildren()) do-- We are getting the contents of Clickers.
    wait()
    Generate.ClickDetector.MouseClick:connect(function() -- This is how I like to set up functions, works just like your way!
        if Generate.BrickColor ~= "Really red" then
            Generate.Parent.Field:ClearAllChildren()-- Generate is the Current part being cycled through..Make sure this Hierarchy is correct!
            local Block = game.Lighting:FindFirstChild(Blocks[math.random(1,#Blocks)])
            local Mine = Block:Clone()
            Mine.Position = Generate.Position
            Mine.Parent = Generate.Parent.Field
        else
            print("Cooling Down, Please wait")
        end
    end)
end

Now, make sure you read my Comments. Please comment any questions and if this answer helps, toss a +1 rep!

P.S. This script can be anywhere. Do not make multiples of this script, it handles every part.

0
Ok, generate is a button that resets the mine, Mine's parent is Field, and the parts the script is cycling through are in a group called MineArea connor12260311 383 — 8y
0
May I get a full Hierarchy list of your build? I need to know if field is also copied 600 times just like the button, or if Field is just an instance in Workspace you can get to by doing game.Workspace.Field- then I can help. alphawolvess 1784 — 8y
0
I will try to explain. So im supposed to have the script in MineArea, which contains all the parts(the parts are called "Part") wich give the generated blocks a position, field is the model wich parents the generated blocks. Generator is a button that you click to Activate the Mine Being generated. connor12260311 383 — 8y
0
Oh, and Field is game.Workspace["Mining Tycoon"].Tycoons.Diamond.Essentials.Mineing.Field connor12260311 383 — 8y
0
I will place my script that i edited into my question body connor12260311 383 — 8y
Ad

Answer this question