Hello,
I am attempting to make a leaderboard Gui that updates when players come and go. So far I have the following script But the problem is that when players enter it does not show the player until the second player is added and when the second player leaves it does not update
What I need it to do is to update when players come in and when players leave but as of right now it will only start showing the players when the second player comes in and it WILL NOT update if the second player leaves the game. It will still show that there are 2 players even thought there is only 1
Thanks in advance for any help provided.
function update() local c = script.Parent:GetChildren() for i = 1,#c do if string.sub(c[i].Name, 1, 8) == "PlayerLabel" then c[i].Visible = false end end for i = 1,#plr do local item = script.Parent:findFirstChild("PlayerLabel" .. tostring(i)) local item2 = script.Parent:findFirstChild("PlayerLabelNum" .. tostring(i)) if (item~=nil) then item.Visible = true item2.Visible = true item.Text = plr[i].Name local Kills = plr[i].leaderstats.Kills Kills.Changed:connect(function() item2.Text = plr[i].leaderstats.Kills.Value end) end end end function getNumber(obj) for i = 1,#plr do if plr[i]==obj then return i end end end plr = {} p = game.Players:GetChildren() for i = 1,#p do table.insert(plr, p[i]) end update() game.Players.ChildAdded:connect(function (guy) table.insert(plr, guy) update() end) game.Players.ChildRemoved:connect(function (guy) table.remove(plr, getNumber(guy)) update() end)