I tried to make a script that inserts a part and if you click it, particles come out then the error says 'then' expected near ','. If anyone can help me, thank you.
x = Instance.new("Part", workspace) c = Instance.new("ClickDetector", x) c.Parent = game.Workspace.x function onTouched(click) function toGood(obj) if i, v in pairs(obj:getChildren()) do if v:IsA("BasePart") then local p = Instance.new("ParticleEmitter", v) p.Texture = "" p.Rate = 5000 p.Lifetime = NumberRange.new(5) p.VelocitySpread = NumberRange.new(100) p.Speed = NumberRange.new(5000) p.Size = NumberSequence.new(50) end toGood(v) end end c.Parent.Touched:connect(onTouched) toGood(workspace)
Line 7:
if i, v in pairs(obj:getChildren()) do
Should be
for i, v in pairs(obj:getChildren()) do
Also, I think you messed up the positions of the functions, but I am not 100% what you are attempting to do. However, I believe you mean this:
x = Instance.new("Part", workspace) c = Instance.new("ClickDetector", x) --c.Parent = game.Workspace.x --c is already parented to x (you did that in the constructor). Also, game.Workspace.x probably does not exist (x is named "Part" by default). function toGood(obj) for i, v in pairs(obj:getChildren()) do --The syntax error if v:IsA("BasePart") then local p = Instance.new("ParticleEmitter", v) p.Texture = "" p.Rate = 5000 p.Lifetime = NumberRange.new(5) p.VelocitySpread = NumberRange.new(100) p.Speed = NumberRange.new(5000) p.Size = NumberSequence.new(50) end toGood(v) end --Also missing an end end function onTouched(click) toGood(workspace) end c.Parent.Touched:connect(onTouched) --Do you want this to be when you touch X or click c? Because this is the former. The latter is c.MouseClick:connect(onTouched)