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

What is wrong with this loot spawning/despawning code?

Asked by 9 years ago

I am not sure how to interpret what the Output said(stated after code). I could be adding too many ends or something, or adding too few or whatever. If I knew I wouldn't be asking. The name of the script is 'L00t'

while wait(10) do
    z = math.random(1,4)
    print(z)
---------------------------------------------------------------------------------------------------
    if z == 1 then
        a = game.Lighting.ScrapCorrodeA:Clone()
        a.Parent = game.Workspace
        wait(5)
            if a.Parent ~= game.Workspace then
            Print("ScrapCorrodeA was picked up!")
            else
            a:Remove()
            end
---------------------------------------------------------------------------------------------------
    elseif z == 2 then
        b = game.Lighting.PipeCorrodeA:Clone()
        b.Parent = game.Workspace
        wait(5)
            if b.Parent ~= game.Workspace then
            Print("PipeCorrodeA was picked up!")
            else
            b:Remove()
            end
---------------------------------------------------------------------------------------------------
    elseif z == 3 then
        c = game.Lighting.FabricA:Clone()
        c.Parent = game.Workspace
        wait(5)
            if c.Parent ~= game.Workspace then
            Print("FabricA was picked up!")
            else
            c:Remove()
            end
            end
--------------------------------------------------------------------------------------------------
    elseif z == 4 then --LINE 36
        d = game.Lighting.SpringA:Clone()
        d.Parent = game.Workspace
        wait(5)
        if d.Parent ~= game.Workspace then
            Print("SpringA was picked up!")
            else
            d:Remove()
        end
end
end

Here is what I got in Output just after testing: 20:26:11.356 - Workspace.L00t:36: 'end' expected (to close 'while' at line 1) near 'elseif'

0
Missing 3 ends. (For all the else ifs) Vescatur 95 — 9y
0
You have an extra end in the third elseif (z == 3, extra on line 33 or 34.) GoldenPhysics 474 — 9y
0
And I also realize that I duplicate a variable and refer to it later on. Spicyhunter3 10 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
while wait(10) do
    z = math.random(1,4)
    print(z)

    if z == 1 then
        a = game.Lighting.ScrapCorrodeA:Clone()
    else if z == 2 then
        a = game.Lighting.PipeCorrodeA:Clone()
    elseif z == 3 then
        a = game.Lighting.FabricA:Clone()
    elseif z == 4 then
        a = game.Lighting.SpringA:Clone()
    end

    a.Parent = game.Workspace
    wait(5)

    if a.Parent ~= game.Workspace then
        Print("Item was picked up!")
    else
        a:Remove()
    end
end

That should help a bit. You had and extra end (as I stated in my comment), but you mainly had the same piece of code four times, so by using the if and elseifs only on the part that was different, I shortened the code and made it easier to understand.

Feel fee to comment with any questions, accept the answer and/or vote it up if you find this helpful. Thanks!

Ad

Answer this question