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

_G.Dead is a nil value??

Asked by 6 years ago

In a script for my game, I defined a table by saying:

_G.Dead = {}

As you can see, its a global table and has no values in it yet. I connected the players humanoid to the died event and add their name to the table like this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()
            for i, v in pairs(_G.Players) do
                if v == plr.Name then
                    table.remove(_G.Players, i) -- Another table that actually works...
                    table.insert(_G.Dead, v)
                end
            end
        end)
    end)
end)

These scripts don't error out, the died function seems to have no trouble inserting a value into the table, but when I try to print "_G.Dead[1]", it says that I tried to define a nil value "_G.Dead". Thanks in advance for finding the error.

-Cmgtotalyawesome

0
Why make it global? NexanianStudios 91 — 6y
0
@NexanianStudios I need to use it for math equations in other scripts, but can't have the table in there... cmgtotalyawesome 1418 — 6y

Answer this question