What I mean is, is there a way to instead of having a script in a lava brick and copying it to other places I might want can I instead have one single script where it detects if it's touched.
like this
brick -script brick -script brick -script brick -script
is that a way to reduce this like:
brick brick brick brick Script(PARENT IS WORKSPACE)
You can put all of your lava parts in one model and do like this in one script:
1 | for i,v in next ,Workspace.LavaParts:GetChildren() do |
2 | v.Touched:connect( function (hit) |
3 | --your code |
4 | end ) |
5 | end |
Yup! In fact, I even think this is better in terms of efficiency and CPU usage. But let's not get technical and let's answer your question.
01 | function CreateLavabrick() |
02 | local new = Instance.new( "Part" , game.Workspace) |
03 | new.Name = "Laval" |
04 | new.BrickColor = BrickColor.Red() |
05 | new.Anchored = true |
06 | new.Touched:connect( function (p) |
07 | if p.Parent:FindFirstChild( "Humanoid" ) then |
08 | p.Parent.Humanoid.Health = - 1 |
09 | end |
10 | end ) |
11 | return new |
12 | end |
13 |
14 | -- For example, create 100 lava bricks and move them to a random location! |
15 |
16 | for i = 1 , 100 do |
17 | local lava = CreateLavabrick() |
18 | lava.CFrame = CFrame.new(Vector 3. new(math.random(- 100 , 100 ), 2 , math.random(- 100 , 100 )) |
19 | end |