Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help With LeaderBoard Gui Wont Update When Players Leave?

Asked by 6 years ago

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)
0
It's probably because by the time the script has detected that the player has left, all the player's data is gone, I suggest storing a single data value associated with the player (their name/id) in RS or SS, so when the player leaves the server can use that value and then delete it. CPF2 406 — 6y
0
But Even if the players data is gone It shouldn't matter. I dont want it to show the players data anymore. I just want it to make it disappear off of the other players screens. So when a player leaves it gets rid of the name CrazyRoblots 13 — 6y

Answer this question