Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I shorten this script?

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

✓ Accepted 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

This discussion is preserved as it was. New answers, comments, and votes are closed.