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

How do I make it so my game doesn't break when people leave?

Asked by 4 years ago
Edited 4 years ago

So I have a ton of for loops in my game and whenever people leave they sometimes break. I know I could check if the thing I want to change is nil but I think I would have to do that a lot of times.

Here is ONE of my current for loops

for i, v in pairs(game.Players:GetChildren()) do
    v.PlayerGui.GameNotifications.Frame.TextLabel.Text = "It was... a tie! Nobody wins or gets any points!"
end

The only way I can think of making that not get an error when someone leaves when it is running is by doing:

        if winner == "None" then
            for i, v in pairs(game.Players:GetChildren()) do
                if v:FindFirstChild("PlayerGui") ~= nil then
                    if v.PlayerGui:FindFirstChild("GameNotifications") ~= nil then
                        if v.PlayerGui.GameNotifications:FindFirstChild("Frame") ~= nil then
                            if v.PlayerGui.GameNotifications.Frame:FindFirstChild("TextLabel") ~= nil then
                                v.PlayerGui.GameNotifications.Frame.TextLabel.Text = "It was... a tie! Nobody wins or gets any points!"
                            end
                        end
                    end
                end
            end
        end

What is a better way error-proof this?

0
Check the output, it still prints errors when you leave the test server. Azarth 3141 — 4y
0
@Azarth It doesn't if I do the second one but I was wondering if there was a better way to do it. xXGokyXx 46 — 4y

Answer this question