So I have a Model of a couple of bricks and I want the script to add explosions to every brick but randomly and with a random time. I have tried to do it but it wont work. Here is what I have :
local g = script.Parent.Parent.Fire:GetChildren() for i = 1, #g do local f = Instance.new("Explosion", script.Parent) f.Position = i[g] f.BlastPressure = 0 f.BlastRadius = 20 local s = script.Parent.Explosion2 s:Play() wait(math.random(1,3)) end end end
Output: Workspace.Model.Model.Script:4: attempt to index local 'i' (a number value)
You were trying to make the position of the explosion as the number of (g) in the table(i) That should be reversed to g[i] not i[g] Ex: table[number] You also forgot to add the .Position after the g[i]. Also, you weren't parenting the explosion to the part, you were parenting it to whatever the script is in I parented each explosion to the part it belongs to Lastly, you had too many ends, you should only have one end.
local g = script.Parent.Parent.Fire:GetChildren() for i = 1, #g do local f = Instance.new("Explosion", g[i]) -- parenting each explosion to the part it belongs to f.BlastPressure = 0 f.BlastRadius = 20 f.Position = g[i].Position -- positioning it to the part it belongs to local s = script.Parent.Explosion2 s:Play() wait(math.random(1,3)) end
That's basically all, you were on the right track! Hope I helped :D