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
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.