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

Can't get this script to insert fire and smoke into these bricks?

Asked by 8 years ago

Hello. Just to get this off first, I don't really have any experience scripting in .lua. So, there's probably a lot wrong with this script. What I'm trying to do is get it so when the on button is touched, it inserts smoke and fire into the bricks listed. Right now it doesn't do that.

Model layout: http://prntscr.com/bc9zbc

Code:

local b = script.Parent.Parent.FireB
local c = script.Parent.Parent.FireC
local d = script.Parent.Parent.FireD
local e = script.Parent.Parent.FireE
local f = script.Parent.Parent.FireF
local g = script.Parent.Parent.FireG
local h = script.Parent.Parent.FireH
local fir = Instance.new("Fire",b,c,d,e,f,g)
local smo = Instance.new("Smoke",b,c,d,e,f,g)

function onClicked()
    print "Fire on"
    fir = Instance.new("Fire",b,c,d,e,f,g)
    smo = Instance.new("Smoke",b,c,d,e,f,g)




    script.Parent.Parent.b.Fire.Size = 25
    script.Parent.Parent.b.Smoke.Size = 20
    script.Parent.Parent.b.Smoke.Color = "Black"
    script.Parent.Parent.b.Smoke.RiseVelocity = 3

    script.Parent.Parent.c.Fire.Size = 25
    script.Parent.Parent.c.Smoke.Color = "Black"
    script.Parent.Parent.c.Smoke.Size = 20
    script.Parent.Parent.c.Smoke.RiseVelocity = 3

    script.Parent.Parent.d.Fire.Size = 25
    script.Parent.Parent.d.Smoke.Color = "Black"
    script.Parent.Parent.d.Smoke.Size = 20
    script.Parent.Parent.d.Smoke.RiseVelocity = 3

    script.Parent.Parent.e.Fire.Size = 25
    script.Parent.Parent.e.Smoke.Color = "Black"
    script.Parent.Parent.e.Smoke.Size = 20
    script.Parent.Parent.e.Smoke.RiseVelocity = 3

    script.Parent.Parent.f.Fire.Size = 25
    script.Parent.Parent.f.Smoke.Color = "Black"
    script.Parent.Parent.f.Smoke.Size = 20
    script.Parent.Parent.f.Smoke.RiseVelocity = 3

    script.Parent.Parent.g.Fire.Size = 25
    script.Parent.Parent.g.Smoke.Color = "Black"
    script.Parent.Parent.g.Smoke.Size = 20
    script.Parent.Parent.g.Smoke.RiseVelocity = 3

    script.Parent.Parent.h.Fire.Size = 25
    script.Parent.Parent.h.Smoke.Color = "Black"
    script.Parent.Parent.h.Smoke.Size = 20
    script.Parent.Parent.h.Smoke.RiseVelocity = 3
end

script.Parent.Touched:connect(onClicked)


1 answer

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

You can only use two arguments in Instance.new(). The object you want to create, and the parent of the new object.

You're also using Smoke Color improperly as it is a Color3 value, not a BrickColor (even if it was you'd need to use BrickColor.new())


Solution

Since it looks like you're wanting to make multiple of the same parts, what you could do is put all the parts you defined into a table. Then you would be able to use a for loop to go through all elements of the table and create the new items.

You would need to use Color3.new(r/255, g/255, b/255) since all arguments of Color3.new() are floats they have to be between 0 and 1. Alternatively, you can use the new function Color3.fromRGB and use whole numbers from there.


Final Script

local PartsToSetAblaze = {
    script.Parent.Parent.FireB,
    script.Parent.Parent.FireC,
    script.Parent.Parent.FireD,
    script.Parent.Parent.FireE,
    script.Parent.Parent.FireF,
    script.Parent.Parent.FireG,
    script.Parent.Parent.FireH,
    --You can add more parts here.
}

function onClicked()
    print "Fire on"
    for Index, Value in pairs(PartsToSetAblaze) do --Index and Value are just variables. You can name these however you want. Index is the number the value is in the table. The value is the actual object or value in the table.
        if Value ~= nil then --We just want to make sure that the part still exists, otherwise the script may error.
            local fir = Instance.new("Fire",Value) --Create new fire object and put it in the brick.
            fir.Size = 25 --We can use the variable and change the size immediately.
            local smo = Instance.new("Smoke",Value)
            smo.Size = 20
            smo.Color = Color3.new(255/255, 255/255, 255/255) --You could do 1,1,1 But I jsut wanted to emphasize that Color3.new arguments are floats and shoud be between 0 and 1.
            smo.RiseVelocity = 3
        end
    end
end

script.Parent.Touched:connect(onClicked)

Hopefully this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, feel free to comment below and I will get back to you.
0
On a side note it doesn't make much sense to name the function for a touched event OnClicked Perci1 4988 — 8y
0
Just one quick side thing, this works and thank you so much! But for the off button, what would the code look like to remove the smoke and fire? Thanks! alexduskthorn 40 — 8y
0
local PartsToExtinguish = {--PartsHere} for _,v in pairs(PartsToExtinguish) do if v:FindFirstChild("Fire") then v.Fire:Destroy() end if v:FindFirstChild("Smoke") then v.Smoke:Destroy() end end --This is a little inefficient, but I'm not willing to provide a completely efficient script unless I see attempt at revision. M39a9am3R 3210 — 8y
0
Got the off script to work! Thanks so much! alexduskthorn 40 — 8y
Ad

Answer this question