Hello,

I have a problem with my Global Death Script. I'ts the script that comes from AlvinBlox's Rounds tutorial series. I believe this error is throwing off other features of my game, most notably, the DataStore.

When a character is killed, or when they do a Player Reset, this error appears: -- Line 5 "bad argument #1 to 'pairs()' (table expected, got nil) "

How do I fix this error? My Global Death Script is below, I've marked the line that errors:

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild('Humanoid').Died:connect(function()
			local Update = {}
			for i,v in pairs(_G.gameplayers) do --ERROR LINE
				if v ~= player.Name then
					table.insert(Update, 1,v)
				end
			end
			_G.gameplayers = Update
		end)
	end)
end)

_G.gameplayers is defined in the Main Script in ServerScriptService:


-- Round System Setup

_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v then
table.insert(_G.gameplayers, v.Name)
end 
end

--Intermission
--Map Selection
-- Round
-- Repeat

2 comments

0

I don't see _G.gameplayers being defined.

0

Thanks for the comment! I've edited the original question with that information.