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

How can I make the button create particles when clicked?

Asked by
Java_0 5
8 years ago
Edited 8 years ago

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)

1 answer

Log in to vote
0
Answered by 8 years ago

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)
0
Thanks sir, I highly appreciate your help. :D Java_0 5 — 8y
Ad

Answer this question