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 make game where you are in a deserted island, and you have to find recourses and stuff…
What is the issue? Include screenshots / videos if possible!
when the player dies the player is not getting removed from the PlayerInRound Table
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes
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!
this is the script, i put prints for debugging
local PlayersInRound = {}
local PlayersInLobby = {}
local Information = game.ReplicatedStorage.Values.Information
local MiniInformation = game.ReplicatedStorage.Values.MiniInformation
local RoundStarted = game.ReplicatedStorage.Values.RoundStarted
game.Players.PlayerAdded:Connect(function(plr)
MiniInformation.Value = plr.Name.." has joined"
if RoundStarted.Value == true then
table.insert(PlayersInRound,plr)
end
end)
local function PlayerDeath(plr: Player, index: number)
table.insert(PlayersInLobby,plr)
table.remove(PlayersInRound,index)
print("Passssssssssssss")
end
while wait() do
local AmountPlayers = #game.Players:GetPlayers()
if AmountPlayers <= 1 then
Information.Value = "Need More Players "..AmountPlayers.."/2!"
else
if RoundStarted.Value == false then
for i = 30,0,-1 do
wait(1)
if i <= 10 then
Information.Value = "Round is starting soon!"
else
Information.Value = "Round is starting In "..i.." seconds!"
end
end
Information.Value = "Round Started!"
wait(3)
Information.Value = ""
RoundStarted.Value = true
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(PlayersInRound,v)
local Index = table.find(PlayersInRound,v,nil)
print(Index,v)
v.Character:FindFirstChildWhichIsA("Humanoid").Died:Connect(function()
print(#PlayersInRound)
print(#PlayersInLobby)
PlayerDeath(v,Index)
print(#PlayersInLobby)
print(#PlayersInLobby)
print("PlayerDied1")
end)
end
end
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local PlayersInRound = {}
local PlayersInLobby = {}
local Information = game.ReplicatedStorage.Values.Information
local MiniInformation = game.ReplicatedStorage.Values.MiniInformation
local RoundStarted = game.ReplicatedStorage.Values.RoundStarted
game.Players.PlayerAdded:Connect(function(plr)
MiniInformation.Value = plr.Name.." has joined"
if RoundStarted.Value == true then
local userId: number = plr.UserId
PlayersInRound[userId] = true :: boolean
end
end)
local function PlayerDeath(plr: Player)
local userId: number = plr.UserId
PlayersInRound[userId] = nil
PlayersInLobby[userId] = true :: boolean
print("Passssssssssssss")
end
while wait() do
local AmountPlayers = #game.Players:GetPlayers()
if AmountPlayers <= 0 then
Information.Value = "Need More Players "..AmountPlayers.."/2!"
else
if RoundStarted.Value == false then
for i = 30,0,-1 do
wait(1)
if i <= 10 then
Information.Value = "Round is starting soon!"
else
Information.Value = "Round is starting In "..i.." seconds!"
end
end
Information.Value = "Round Started!"
wait(3)
Information.Value = ""
RoundStarted.Value = true
for i,v in pairs(game.Players:GetPlayers()) do
local userId: number = v.UserId
PlayersInRound[userId] = true :: boolean
v.Character:FindFirstChildWhichIsA("Humanoid").Died:Connect(function()
print(#PlayersInRound)
print(#PlayersInLobby)
PlayerDeath(v)
print(#PlayersInRound)
print(#PlayersInLobby)
print("PlayerDied1")
end)
end
end
end
end
You’re putting the player in the game as soon as they join:
game.Players.PlayerAdded:Connect(function(plr)
if RoundStarted.Value == true then
local userId: number = plr.UserId
PlayersInRound[userId] = true :: boolean
end
end)
local function PlayerDeath(plr: Player, index: number)
table.insert(PlayersInLobby,plr)
table.remove(PlayersInRound, table.find(PlayersInRound, plr))
print("Passssssssssssss")
end
I’m unfortunately unable to help you with your round system. I answered the title’s question, which was ‘Player not getting removed from table’ which seemed like the main concern to me.
Honestly hate that you have to do that weird table.find stuff. I wish it would check for both the number index and try to find it in the table automatically before erroring.
The thing is that when using table.remove(), it will only find the index of an array and removes the item if it is on that index, which is why i added table.find() instead.
( Sorry for bumping ) Yeah I just have those odd ‘phases’ where the style I program in drastically changes and I normally stick to them for a while before I realize I hate the style and I want to replace it again.
I know that. That’s why I’m saying that table.remove() checked for a number index, then automatically do something similar to table.find() instead of having to do it yourself since it looks messy.
That’s fair. Not trying to criticize your style, I’m just wondering since I’m trying to get into type-checking (for a host of reasons) and I was unsure of why you would type-check a static boolean.