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

How could I shorten this script?

Asked by 8 years ago

This script would continue to be very long but I decided to make it shorter for the sake of reading. I would appreciate it if somebody could give me a way to shorten it.

while wait() do
    if script.Parent.Visible == true then
        wait(10)
        script.Parent.Visible = false
        game.Workspace.ZombiesTotal.Value = 5
        while wait() do
            if game.Workspace.ZombiesRemaining == 0 then
                game.Workspace.ZombiesTotal.Value = 10
                while wait() do
                    if game.Workspace.ZombiesRemaining == 0 then
                        game.Workspace.ZombiesTotal.Value = 15
                    end
                end
            end
        end
    else
    end
end

Thanks in advance for any help you may provide!

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

I've explained this to the asker in the Community Chat already.

local currentZombieCount = 0

game.Workspace.ZombiesRemaining.Changed:connect(function(newValue)
    if newValue == 0 then
        script.Parent.Visible = true
    end
end)

while wait() do
    repeat wait() until script.Parent.Visible == true
    currentZombieCount = currentZombieCount + 5
    wait(10)
    game.Workspace.ZombiesTotal.Value = currentZombieCount
    script.Parent.Visible = false
end
Ad

Answer this question