script.Parent.Touched:Connect(function(plr)
print("Touched!")
print(_G.players)
for i = 1, #_G.players do
if _G.players[i] == plr.Name then
print(plr.Name .. " has died!")
print(_G.players)
end
end
end)
It’s a table where player names get stored every round. In the script it’s just
_G.players = {}
This is the block of code that stores the table elements each round:
Players = game:GetService("Players")
for i, player in pairs(Players:GetPlayers()) do
print(player.Name)
table.insert(_G.players, #_G.players + 1, player.Name)
end
i think you havnt remove the player from the table here
for i = 1, #_G.players do
if _G.players[i] == plr.Name then
print(plr.Name .. " has died!")
print(_G.players)
local found = table.find(_G.players,plr.name)
table.remove(_G.players, found)
end
end
There are no errors in the output and the table nor the string is outputing:
Expected result: Kostiskat has died! {}(Empty table because player was removed from it)
Perhaps I should probably mention that. The script is inside a touched event:
script.Parent.Touched:Connect(function(plr)
for i = 1, #_G.players do
if _G.players[i] == plr.Name then
print(plr.Name .. " has died!")
print(_G.players)
local found = table.find(_G.players,plr.name)
table.remove(_G.players, found)
end
end
end)
maybe add a break after it because it shouldnt print nothing:
script.Parent.Touched:Connect(function(plr)
for i = 1, #_G.players do
if _G.players[i] == plr.Name then
print(plr.Name .. " has died!")
print(_G.players)
local found = table.find(_G.players,plr.name)
table.remove(_G.players, found)
break
end
end
end)
The part is supposed to teleport you to the lobby without killing you, as it makes it easier for me to just remove them from the table easily. (The teleport block of code is not intergrated yet)
script.Parent.Touched:Connect(function(plr)
if table.find(_G.players, plr.Name) then
print(plr.Name.." has died!")
table.remove(_G.players, table.find(_G.players, plr.Name))
end
end)