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 to store players (plr1, plr2…) in a table
-
What is the issue? Include screenshots / videos if possible!
Roblox continues with the if statement, meaning that there is a player. But when trying to store that player in a table, it gives an error that states the table cannot save a nil value
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Setting all the values to nil at the beginning but that didn’t work, printing the player’s names and position to see it there is an error there but it shows the names and locations correctly. I just have no idea how or why this doesn’t work.
if plr1 ~= nil then
table.insert(playertable,plr1)
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
2 Likes
save the player instead and then get character if you want to
1 Like
My bad on the wording in the original post, I am saving the players, not characters
how are you so sure that it saves character but gives nil, did you try debugging?
Because when I print the player’s name, it shows it. If there was no player saved then it would have not have printed anything at all
This is the code I used to check if there is a player saved:
plr1 = nil
plr2 = nil
plr3 = nil
plr4 = nil
plr5 = nil
plr6 = nil
plr7 = nil
plr8 = nil
Player1 = nil
Player2 = nil
Player3 = nil
Player4 = nil
Player5 = nil
Player6 = nil
Player7 = nil
Player8 = nil
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 .." is Player1")
end
if Player2 ~= nil then
plr2 = game.Players:GetPlayerFromCharacter(Player2.Parent)
print(plr2.Name .." is Player2")
end
if Player3 ~= nil then
plr3 = game.Players:GetPlayerFromCharacter(Player3.Parent)
print(plr3.Name .." is Player3")
end
if Player4 ~= nil then
plr4 = game.Players:GetPlayerFromCharacter(Player4.Parent)
print(plr4.Name .." is Player4")
end
if Player5 ~= nil then
plr5 = game.Players:GetPlayerFromCharacter(Player5.Parent)
print(plr5.Name .." is Player5")
end
if Player6 ~= nil then
plr6 = game.Players:GetPlayerFromCharacter(Player6.Parent)
print(plr6.Name .." is Player6")
end
if Player7 ~= nil then
plr7 = game.Players:GetPlayerFromCharacter(Player7.Parent)
print(plr7.Name .." is Player7")
end
if Player8 ~= nil then
plr8 = game.Players:GetPlayerFromCharacter(Player8.Parent)
print(plr8.Name .." is Player8")
end
i think
Player1 = nil
Player2 = nil
Player3 = nil
Player4 = nil
Player5 = nil
Player6 = nil
Player7 = nil
Player8 = nil
this part is unnecessary because you already defined the variables below without using any sort of wait()
Yea I tried to do this as a solution, the error was already there before though
plr1 = game.Players:GetPlayerFromCharacter(Player1.Parent)
i think you meant to get the Children, not the Parent, because you would be getting “seat5”
Isn’t Player1 a Humanoid? which should mean that if I get the parent the result is a character
soo “Occupant” is a humanoid? who is “seat5” then? i don’t think humanoids are named “Occupant”
Seat5 is a seat, I am checking who is sitting on that seat and storing him in a Player# variable
HOW did you check who is sitting on Seat5? If you’re using a StringValue then you’re gonna have to add more sanity checks.
Player1 = seat5.Occupant
Player2 = seat1.Occupant
Player3 = seat7.Occupant
Player4 = seat2.Occupant
Player5 = seat4.Occupant
Player6 = seat3.Occupant
Player7 = seat6.Occupant
Player8 = seat8.Occupant
so I should check if the seat occupant is nil and only then save the Player#?
So occupant was a value? Use seat5.Occupant.Value and get the player using a loop
I’ll try that in a bit, have to go afk
1 Like
No its a property of a seat that gets the humanoid that is sitting on it
local seat1 = workspace.ChairModel1.Seat
local seat2 = workspace.ChairModel2.Seat
local seat3 = workspace.ChairModel3.Seat
local seat4 = workspace.ChairModel4.Seat
local seat5 = workspace.ChairModel5.Seat
local seat6 = workspace.ChairModel6.Seat
local seat7 = workspace.ChairModel7.Seat
local seat8 = workspace.Chair.ChairModel8.Seat
i see, i should have known. which seat were you sitting at when you were debugging?
Will send screenshots in a minute to understand better
1 Like
Dont get confused by the Player3 is Player6 and similar. Player3 and Player2 are usernames while Player6 and Player7 is what their variable is in the code