You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want a table “playertable” to store the current players that are sitting
-
What is the issue? Include screenshots / videos if possible!
It keeps telling me that I am trying to store a nil value, even though the 2 players that got printed are obviously not nil!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’m not even sure how to fix this, I just simply have no idea as the error itself makes no sense to me
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Player1 = seat5.Occupant
Player2 = seat1.Occupant
Player3 = seat7.Occupant
Player4 = seat2.Occupant
Player5 = seat4.Occupant
Player6 = seat3.Occupant
Player7 = seat6.Occupant
Player8 = seat8.Occupant --getting each player from their given seats
local playertable = {}
local playerseat = {}
if Player1 ~= nil then
plr1 = game.Players:GetPlayerFromCharacter(Player1.Parent) --getting character from each player to display it
print(plr1.Name)
end
if Player2 ~= nil then
plr2 = game.Players:GetPlayerFromCharacter(Player2.Parent)
print(plr2.Name)
end
if Player3 ~= nil then
plr3 = game.Players:GetPlayerFromCharacter(Player3.Parent)
print(plr3.Name)
end
if Player4 ~= nil then
plr4 = game.Players:GetPlayerFromCharacter(Player4.Parent)
print(plr4.Name)
end
if Player5 ~= nil then
plr5 = game.Players:GetPlayerFromCharacter(Player5.Parent)
print(plr5.Name)
end
if Player6 ~= nil then
plr6 = game.Players:GetPlayerFromCharacter(Player6.Parent)
print(plr6.Name)
end
if Player7 ~= nil then
plr7 = game.Players:GetPlayerFromCharacter(Player7.Parent)
print(plr7)
end
if Player8 ~= nil then
plr8 = game.Players:GetPlayerFromCharacter(Player8.Parent)
print(plr8)
end
if plr1 ~= nil then --Saving the characters in a table to not use the y variable; OUTDATED METHOD
table.insert(playertable,plr1) --Where the problem occurs, which makes no sense to me as plr1 is nil, which means the table shouldn't insert anything
end
if plr2 ~= nil then
table.insert(playertable,plr2)
end
if plr3 ~= nil then
table.insert(playertable,plr3)
end
if plr4 ~= nil then
table.insert(playertable,plr4)
end
if plr5 ~= nil then
table.insert(playertable,plr5)
end
if plr6 ~= nil then
table.insert(playertable,plr6)
end
if plr7 ~= nil then
table.insert(playertable,plr7)
end
if plr8 ~= nil then
table.insert(playertable,plr8)
end
The only ones getting printed are Player8 and Player6 as they are the only ones sitting. I have no idea how or why even after being told that if the player is not nil, dont save him, the table is trying to save Player1, Player2… and so on
Edit: Setting the plr1 to plr8 values to nil at the beginning doesn’t help