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

How can I fix my script to allow objects on fire to explode?

Asked by 7 years ago

Hello, I posted this, but it didn't post, so now I'm posting it again...

I am very new to scripting, and have been following the tutorials provided by Roblox. In the tutorials, you make an object that lights other objects on fire when they come in contact. You also create a block that removes the fire. Here they are...

Fire, I set the variable at the top because it was giving a warning.

fire = ""
function lightOnFire(part)
    print("Going to light this part on fire:")
    print(part.Name)

    fire = Instance.new("Fire")
    fire.Parent = part

end

firePart = game.workspace.FirePart
firePart.Touched:connect(lightOnFire)

Water

fire = ""
function putOutFire(part)
    print("Going to put out fire on:")
    print(part.Name)

    fire = part:FindFirstChild("Fire")
    if fire then
        fire:Destroy()
    end
end

waterPart = game.workspace.WaterPart
waterPart.Touched:connect(putOutFire)

These are my outcomes from the tutorial. They work fine, as well as the explosion files, I combined my knowledge from the fire tutorial and the explosion tutorial. Here is my outcome from the explosion tutorial..

Explosion

number = 0
explosion = ""

function ExplodePart(part)
    if part.BrickColor == BrickColor.Red() then
        explosion = Instance.new("Explosion", game.Workspace)
        explosion.Position = part.Position
        part.BrickColor = BrickColor.White()
    else
        number = math.random(1,3)
        if number == 1 then
            part.BrickColor = BrickColor.Red()
        end
    end 
end

children = game.Workspace:GetChildren()
while true do
    for _, child in ipairs(children) do
        if child.Name == "ExplosionPart" then
            ExplodePart(child)
        end
    end
    wait(1)
end

Now here is the script I'm having issues with, The script analysis gives no issues, but when I start the game...

firePart = game.workspace.FirePart

waterPart = game.workspace.WaterPart

firePart.Transparency = 1
waterPart.Transparency = 1
-- Seperation of variables not related to fire explosions.
local boom = false
local number = 0
fire = ""

function ExplodePart2(part)
    if boom == true then
        local fireexplosion = Instance.new("Explosion", game.Workspace)
         fireexplosion.Position = part.Position
        local boom = false
        foundFire = false
    else
        local number = math.random(1,3)
        if number == 1 then
            local boom = true
        end
    end 
end

function findFire(part)
    fire = children:FindFirstChild("Fire")
    if fire then
        print("Found fire on:")
        print(part.Name)
        foundFire = true
    end
end

children = game.Workspace:GetChildren()
while true do
    for _, child in ipairs(children) do
        findFire()
        if foundFire == true then
            ExplodePart2(child)
        end
    end
    wait(1)
end
-- End of Fire Explosions.

Errors:

16:29:41.839 - Auto-Saving...
16:29:43.042 - ServerScriptService.Main:27: attempt to call method 'FindFirstChild' (a nil value)
16:29:43.043 - Stack Begin
16:29:43.043 - Script 'ServerScriptService.Main', Line 27 - global findFire
16:29:43.043 - Script 'ServerScriptService.Main', Line 38
16:29:43.043 - Stack End

Me, being the noob I am, doesn't know what this means other than that here is errors in those lines.

Any help would be appreciated. Basically what I'm trying to do is: when a part is on fire, roll a random number and if that number is 1, then initiate the explosion of that part, then disable the explosion so it doesn't blow up multiple times. Sounds simple enough.

So, How would I fix this and achieve me goal?

Thanks in advance.

0
Where is this script that you're having issues with placed? Also, what type of script is it? KingLoneCat 2642 — 7y
0
Did you even write this? User#11440 120 — 7y
0
I did write this, The script is placed in the ServerScriptService. I did some more of the tutorials and have a better understanding. I see that the findfirstchild isn't existent. Not sure what else to say. Dekadrachm 50 — 7y

1 answer

Log in to vote
0
Answered by
AmWrath 41
7 years ago
for _, v in next, workspace:GetChildren() do
if v.ClassName == 'Fire' then
local random = Instance.new(IntValue, v.Parent)
wait(1)
random.Value = math.random(1,10)
if random.Value == 5 then
local explode = Instance.new('Explosion', v.Parent)
end
end
end

Something like this?

0
lol idk, maybe like I said I'm a complete noob and can only understand half of what you wrote Dekadrachm 50 — 7y
Ad

Answer this question