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

Why is 'end' expected at line 357?

Asked by 8 years ago

For my upcoming game Christmas Breakdown , I've tried to make it so that each server expires after 3 days. Most of the script has worked, but there's one problem. At the end (literally, the term 'end'), it says its supposed to be on Line 357. I can't figure out why it does this, and I want to make sure the game ends without messing with any of the data stores. (The problem is at the end of the script, so you can just scroll through it.)

local warning = game.workspace.serverclose.Countdown.SurfaceGui.TextLabel

wait(86400)

warning.Text = "2 Days"

wait(86400)

warning.Text = "1 Day"

wait(14400)

warning.Text = "20 Hours"

wait(18000)

warning.Text = "15 Hours"

wait(18000)

warning.Text = "10 Hours"

wait(3600)

warning.Text = "9 Hours"

wait(3600)

warning.Text = "8 Hours"

wait(3600)

warning.Text = "7 Hours"
warning.TextColor3 = Color3.new(255, 255, 0)

wait(3600)

warning.Text = "6 Hours"

wait(3600)

warning.Text = "5 Hours"

wait(3600)

warning.Text = "4 Hours"

wait(3600)

warning.Text = "3 Hours"

wait(3600)

warning.Text = "2 Hours"

wait(3600)

warning.Text = "1 Hour"
warning.TextColor3 = Color3.new(255, 0, 0)

wait(1800)

warning.Text = "30 Minutes"

wait(300)

warning.Text = "25 Minutes"

wait(300)

warning.Text = "20 Minutes"

wait(300)

warning.Text = "15 Minutes"

wait(300)

warning.Text = "10 Minutes"

wait(60)

warning.Text = "9 Minutes"

wait(60)

warning.Text = "8 Minutes"

wait(60)

warning.Text = "7 Minutes"

wait(60)

warning.Text = "6 Minutes"

wait(60)

warning.Text = "5 Minutes"

wait(60)

warning.Text = "4 Minutes"

wait(60)

warning.Text = "3 Minutes"

wait(60)

warning.Text = "2 Minutes"

wait(60)

warning.Text = "1 Minute"

wait(1)

warning.Text = "59 Seconds"

wait(1)

warning.Text = "58 Seconds"

wait(1)

warning.Text = "57 Seconds"

wait(1)

warning.Text = "56 Seconds"

wait(1)

warning.Text = "55 Seconds"

wait(1)

warning.Text = "54 Seconds"

wait(1)

warning.Text = "53 Seconds"

wait(1)

warning.Text = "52 Seconds"

wait(1)

warning.Text = "51 Seconds"

wait(1)

warning.Text = "50 Seconds"

wait(1)

warning.Text = "49 Seconds"

wait(1)

warning.Text = "48 Seconds"

wait(1)

warning.Text = "47 Seconds"

wait(1)

warning.Text = "46 Seconds"

wait(1)

warning.Text = "45 Seconds"

wait(1)

warning.Text = "44 Seconds"

wait(1)

warning.Text = "43 Seconds"

wait(1)

warning.Text = "42 Seconds"

wait(1)

warning.Text = "41 Seconds"

wait(1)

warning.Text = "40 Seconds"

wait(1)

warning.Text = "39 Seconds"

wait(1)

warning.Text = "38 Seconds"

wait(1)

warning.Text = "37 Seconds"

wait(1)

warning.Text = "36 Seconds"

wait(1)

warning.Text = "35 Seconds"

wait(1)

warning.Text = "34 Seconds"

wait(1)

warning.Text = "33 Seconds"

wait(1)

warning.Text = "32 Seconds"

wait(1)

warning.Text = "31 Seconds"

wait(1)

warning.Text = "30 Seconds"

wait(1)

warning.Text = "29 Seconds"

wait(1)

warning.Text = "28 Seconds"

wait(1)

warning.Text = "27 Seconds"

wait(1)

warning.Text = "26 Seconds"

wait(1)

warning.Text = "25 Seconds"

wait(1)

warning.Text = "24 Seconds"

wait(1)

warning.Text = "23 Seconds"

wait(1)

warning.Text = "22 Seconds"

wait(1)

warning.Text = "21 Seconds"

wait(1)

warning.Text = "20 Seconds"

wait(1)

warning.Text = "19 Seconds"

wait(1)

warning.Text = "18 Seconds"

wait(1)

warning.Text = "17 Seconds"

wait(1)

warning.Text = "16 Seconds"

wait(1)

warning.Text = "15 Seconds"

wait(1)

warning.Text = "14 Seconds"

wait(1)

warning.Text = "13 Seconds"

wait(1)

warning.Text = "12 Seconds"

wait(1)

warning.Text = "11 Seconds"

wait(1)

warning.Text = "10 Seconds"

wait(1)

warning.Text = "9 Seconds"

wait(1)

warning.Text = "8 Seconds"

wait(1)

warning.Text = "7 Seconds"

wait(1)

warning.Text = "6 Seconds"

wait(1)

warning.Text = "5 Seconds"

wait(1)

warning.Text = "4 Seconds"

wait(1)

warning.Text = "3 Seconds"

wait(1)

warning.Text = "2 Seconds"

wait(1)

warning.Text = "1 Seconds"

wait(1)

warning.Text = "0 Seconds"

local function Shutdown()

local Players = game:GetService("Players");
local AllPlayers = Players:GetPlayers();
local Message = "Sorry, this server has met its expiration date."

for I = 1, #AllPlayers do
AllPlayers[I]:Kick(Message);
end

Players.PlayerAdded:connect(function(Player)
Player:Kick(Message)
end)

game.OnClose = function()
wait(10);
end
0
for i = 59,0,-1 do wait(1) warning.Text = i .. " Seconds" end Happywalker 185 — 8y
0
I updated my answer to help you reduce the line count here! adark 5487 — 8y

2 answers

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

Holy mother of inefficient coding...

Your problem is that you opened a function on line 357 and never ended it.


EDIT: Last night when I made this I was too tired to help fix it. Now, let's dive in!

For the majority of this, you are doing a lot of repeated countdowns. Only one thing is changing in your text, and you're waiting a constant amount of time between steps. The biggest offender here is the final 60 seconds, which we can reduce down to this:

for i = 59, 0, -1 do
    wait(1)
    warning.Text = i .. " Second" .. (i ~= 1 and "s" or "")
end

This utilizes numeric for loops and string concatenation, saving hundreds of lines!

We can't use this to great effect on every line, so I didn't change the first few lines except for removing whitespace.

Doing that reduces all your code down to this:

local warning = game.workspace.serverclose.Countdown.SurfaceGui.TextLabel
warning.Text = "3 Days"
wait(86400)
warning.Text = "2 Days"
wait(86400)
warning.Text = "1 Day"

wait(14400)
warning.Text = "20 Hours"
wait(18000)
warning.Text = "15 Hours"
wait(18000)
warning.Text = "10 Hours"

for i = 9, 1, -1 do
    warning.Text = i .. " Hour" .. (i ~= 1 and "s" or "")
    if i == 7 then
        warning.TextColor3 = Color3.new(1, 1, 0)
    end
    wait(3600)
end

warning.TextColor3 = Color3.new(255, 0, 0)

wait(1800)
warning.Text = "30 Minutes"

for i = 25, 10, -5 do
    wait(300)
    warning.Text = i .. " Minutes"
end

for i = 9, 1, -1 do
    wait(60)
    warning.Text = i .. " Minute" .. (i ~= 1 and "s" or "")
end

for i = 59, 0, -1 do
    wait(1)
    warning.Text = i .. " Second" .. (i ~= 1 and "s" or "")
end

local function Shutdown()
    local Players = game:GetService("Players");
    local AllPlayers = Players:GetPlayers();
    local Message = "Sorry, this server has met its expiration date."

    for I = 1, #AllPlayers do
        AllPlayers[I]:Kick(Message);
    end

    Players.PlayerAdded:connect(function(Player)
        Player:Kick(Message)
    end)

    game.OnClose = function()
        wait(10);
    end
end

Using some Table manipulation, it's possible to reduce this down even further, but generating the Table to do that would be as inefficient as your original code. But, you can already see how much better this is now!


The bottom of your script - the actual shutdown portion - never runs! Let's fix that:

--snip

--Remove the (uncalled) function, as it would just get called.

local Players = game:GetService("Players");
local Message = "Sorry, this server has met its expiration date."

for _, Player in ipairs(Players:GetPlayers()) do
    Player:Kick(Message)
end

Players.PlayerAdded:connect(function(Player)
    Player:Kick(Message)
end)

--Remove the game.OnClose callback, as it effectively does nothing here.
0
You should *cough* help him make that more efficient. TheDeadlyPanther 2460 — 8y
0
Yeah, I'd like that. I don't know much other than the basics and some random commands. Danielch1234 20 — 8y
0
My comment is helping you to remove at least 200 lines lol Happywalker 185 — 8y
0
Wow... thanks. Danielch1234 20 — 8y
View all comments (2 more)
1
Wait, on line 28, where's the 15 minute mark? Danielch1234 20 — 8y
0
It's inside the loop! 25, 10, -5 gives: 25, 20, 15, 10 adark 5487 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Really? Please read!! Just put the word "end" on line 374! That is why people tab their coding!

Answer this question