Hey there. I am creating a script where all players that are in the game get listed. If someone leaves or gets killed from the game the StringValue gets destroyed. Now, I am doing the Player Leave thing, but the script does not destroy the StringValue.
game.Players.PlayerRemoving:Connect(function(player)
local PlayerFolder = workspace.GameD
local PlayerName = player.Name
PlayerFolder:WaitForChild(PlayerName):Destroy()
local AllPlayer = workspace.AllPlayer
local PlayerCount = workspace.GameD:GetChildren()
local NumberA = 0
for i, user in ipairs(PlayerCount) do
local CompleteName = "User" .. NumberA
if AllPlayer:WaitForChild(CompleteName).Value == PlayerName then
AllPlayer:WaitForChild(CompleteName):Destroy()
print(CompleteName)
else
NumberA = NumberA + 1
end
end
NumberA = 0
end)
When the game starts, every player will get their StringValue. Like "User0", "User1" till User9. The players are counted by created StringValues when they joined.
"Every player gets StringValue at game start"
local PlayerCount = workspace.GameD:GetChildren()
print(PlayerCount)
local NumberC = 0
for i, user in ipairs(PlayerCount) do
local PlayerFile = Instance.new("StringValue")
PlayerFile.Name = "User" .. NumberC
PlayerFile.Parent = workspace.AllPlayer
PlayerFile.Value = user.Name
NumberC = NumberC + 1
print(PlayerFile.Name)
print(PlayerFile.Value)
end
"Every Player who joins gets StringValue"
game.Players.PlayerAdded:Connect(function(player)
local PlayerFolder = workspace.GameD
local Player2 = player
local PlayerSave = Instance.new("StringValue")
PlayerSave.Name = Player2.Name
PlayerSave.Parent = PlayerFolder
end)

3 comments
Well it works good so far, but It still does not destroy the "User0" or for example "User5" StringValue. Thats what I try to do. It should check every Values from the StringValues in the Folder and if the Value matches, it gets destroyed.
Fixed it, It should work fine now.
Thanks, it works fine now!