of     1   

Never2Humble
#223674885Monday, August 14, 2017 10:21 PM GMT

Hello! I keep getting an error with my Global Death Script. The error I get is: -- Line 7 "bad argument #1 to 'pairs()' (table expected, got nil) " I've marked the line where I get the error below: 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) Thoughts? Seems like it should be an easy fix, but I don't know what it is. :D Help is much appreciated. Thanks!
amanda
#223676091Monday, August 14, 2017 10:46 PM GMT

_G.gameplayers is nil whenever your script reads it
Never2Humble
#223677016Monday, August 14, 2017 11:06 PM GMT

Right...how do I fix it? :)
amanda
#223677054Monday, August 14, 2017 11:06 PM GMT

well how about what is _G.gameplayers because your script says it doesn't exist or has no value
Never2Humble
#223678131Monday, August 14, 2017 11:30 PM GMT

Hello amanda! Thanks for the response, but that doesn't quite work. Replacing the line: for i,v in pairs(_G.gameplayers) do with _G.gameplayers Does not solve the problems. I appreciate the Jeopardy answer humor, but please, if you have the solution, provide it in response. :) I wouldn't be posting if I had the answer myself.
Never2Humble
#223680817Tuesday, August 15, 2017 12:29 AM GMT

Anyone else have any ideas? :)
Never2Humble
#223683305Tuesday, August 15, 2017 1:28 AM GMT

Bump?
dude10000009
#223683381Tuesday, August 15, 2017 1:30 AM GMT

She never said replace it, she asked what the value _G.gameplayers is.
Never2Humble
#223684226Tuesday, August 15, 2017 1:48 AM GMT

You're absolutely right. My apologies to Amanda. I immediately assumed negativity when there was none. The _G.gameplayers is the players in the game, it interacts with my main script that calls all the players. From the main script it looks: -- 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
Never2Humble
#223686971Tuesday, August 15, 2017 2:55 AM GMT

Bump.
Never2Humble
#223689732Tuesday, August 15, 2017 3:54 AM GMT

Bump. Anyone?
Never2Humble
#223706048Tuesday, August 15, 2017 2:47 PM GMT

Bump
Never2Humble
#223711157Tuesday, August 15, 2017 5:13 PM GMT

Bump. Anyone got some ideas?
Never2Humble
#223717789Tuesday, August 15, 2017 7:37 PM GMT

Anyone, please? :( This error is wrecking my game, not letting items be saved on the player's death/exit.
Never2Humble
#223720587Tuesday, August 15, 2017 8:34 PM GMT

Bump.
Never2Humble
#223732002Wednesday, August 16, 2017 12:36 AM GMT

Bump.
Never2Humble
#223735172Wednesday, August 16, 2017 1:51 AM GMT

Bump.
Never2Humble
#223740123Wednesday, August 16, 2017 3:39 AM GMT

Bump.
Ajastra
#223740198Wednesday, August 16, 2017 3:41 AM GMT

Hi Never. _G.gameplayers is nil when you are attempting to iterate over it. Pairs iterates over a table. _G.gameplayers is not defined when the code is executing. Additionally, I find that _G is hardly ever necessary and ModuleScripts are much better.
Ajastra
#223740283Wednesday, August 16, 2017 3:43 AM GMT

Also, as a matter of good practice and slight efficiency boost, you can improve your table access by converting its structure to a hash table rather than an array. For example, if we want to check if a player is alive, we should do this: local alivePlayers = { ["PlayerName"] = true } print(alivePlayers["PlayerName"]) Rather than this: local alivePlayers = { "PlayerName" } for key, value in pairs(alivePlayers) do if value == "PlayerName" then print(value) end end
Never2Humble
#223742181Wednesday, August 16, 2017 4:34 AM GMT

Ajastra - Thank you so much for your response!! ...I don't think I got the Global Death Script right, though... XD;;; Help please? game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild('Humanoid').Died:connect(function() local alivePlayers = { ["PlayerName"] = true } print(alivePlayers["PlayerName"]) end) end) end)
Ajastra
#223742506Wednesday, August 16, 2017 4:43 AM GMT

That code would result in a syntax error; my reply was just to show an example of what you could do. What is the intended functionality you want from your script? It appears in the original post you are redefining the _G.gameplayers table for some reason I'm not aware of.
Never2Humble
#223743270Wednesday, August 16, 2017 5:06 AM GMT

Its my Global Death Script, to let the game know people have died. To be honest, its a leftover script from the AlvinBlox Rounds system tutorial I originally used to set up the basis of my Rounds game, and then heavily modified the concept, but the base script was there. I needed a Global Death Script according to the tutorial in addition to a Global Leave Script. But at some point, it started giving me that error message, and I noticed that when the script doesn't work, items purchased by the player don't save either.
Never2Humble
#223743321Wednesday, August 16, 2017 5:07 AM GMT

If there's a better way to go about this, I am absolutely open to ideas. :)
Ajastra
#223743407Wednesday, August 16, 2017 5:09 AM GMT

If you need to track what players are alive, there's no reason not to keep track of this in the main round script. Players leaving can also be tracked there as well. You can even disconnect the events when a round isn't going on if you want to, by calling the RBXScriptSignal:Disconnect() method.

    of     1