Hey devs,
I am currently working a lobby system to teleport players to the main game. Everything worked until now appart from that : I have a list of all the players in the lobby, and I want to remove a player from the list if he leaves, thats what it tried so far, i don’t really understand what’s the issue…
--LocalScript in StarterGui
local frame1 = script.Parent.Lobby1
game.Players.PlayerRemoving:Connect(function(plr)
print(plr)
for i, v in pairs(frame1:GetChildren()) do
if v:IsA('Frame') then
print(v.Name)
if v.Name == plr then
v:Destroy()
end
end
end
end)
Your code works perfectly, but your code does not line up with your intentions.
This is what we call an error in logic, and this is something that doesn’t actually break your script during runtime (which is why it can be difficult to diagnose, in some cases). This script is doing exactly what you’re telling it to do.
You are checking if a string is equal to an instance, which would never equate to true.
Here is your check:
To achieve the wanted result, this should be changed to:
Well it’s something unrelated but instead of looping through all of the children of the frame, you could just directly find it (given it exists) since the child’s name is the player’s name.