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

GUI leaderboard doesn't update player list correctly? (helppppppp)

Asked by
MaxxHD 10
8 years ago
Edited 8 years ago

Okay so i'm pretty sure it has something to do with my upd function

I've made a leaderboard and it works okay but the only problem I have is only players who join after you join appear. So basically it isn't showing players that were in the game before hand it only shows players that join after you. Here's my PlayerAdded script - this goes in the workspace

game.Players.PlayerAdded:connect(function(plr)
    wait()
    playerlist = Instance.new("StringValue", game.Workspace.Players) --This is where the player names are stored
    playerlist.Name = plr.Name
    playerlist.Value = plr.Name
end)

game.Players.PlayerRemoving:connect(function(plr2)
    if game.Workspace.Players:FindFirstChild(plr2.Name) then
        game.Workspace.Players[plr2.Name]:remove()
    end
end)

And here is the script that creates the leaderboard - this goes in my screengui in a frame called "Menu"

Main = script.Parent.Menu
PL = Main.PlayerList
pos = 0

game.Workspace.Players.ChildAdded:connect(function(plr)

function upd()
    getall = PL:GetChildren()

    for i = 1, #getall do
        getall[i].Position = UDim2.new(0, 0, 0, pos)
        pos = pos + 60
    end
    pos = 0
end

    wait()
    Frm = Instance.new("Frame", PL)
    Frm.Name = plr.Name
    Frm.Size = UDim2.new(1, 0, 0, 50)
    Frm.Position = UDim2.new(0, 0, 0, 0)
    Frm.BorderSizePixel = 0
    Frm.BackgroundColor3 = Color3.fromRGB(85, 85, 127)

    IL = Instance.new("ImageLabel", Frm)
    IL.Name = plr.Name
    IL.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username=" ..plr.Name
    IL.Size = UDim2.new(0, 50, 0, 50)
    IL.Position = UDim2.new(1, -60, 0, 0)
    IL.BackgroundTransparency = 1
    IL.BorderSizePixel = 0

    TL = Instance.new("TextLabel", Frm)
    TL.Name = "Name"
    TL.Text = plr.Name
    TL.Size = UDim2.new(1, -100, 0, 50)
    TL.Position = UDim2.new(0, 50, 0, 0)
    TL.FontSize = "Size28"
    TL.Font = "SourceSansLight" 
    TL.BackgroundTransparency = 1
    TL.BorderSizePixel = 0
    TL.TextColor3 = Color3.fromRGB(255, 255, 255)

    LVL = Instance.new("TextLabel", Frm)
    LVL.Name = "Level"
    LVL.Text = "0"
    LVL.Size = UDim2.new(0, 50, 0, 50)
    LVL.Position = UDim2.new(0, 0, 0, 1)
    LVL.FontSize = "Size28"
    LVL.Font = "Arial"
    LVL.BackgroundTransparency = 1
    LVL.BorderSizePixel = 0
    LVL.TextColor3 = Color3.fromRGB(255, 255, 255)

    upd()       

end)


game.Workspace.Players.ChildRemoved:connect(function(plr2)
    if PL:FindFirstChild(plr2.Name) then
        PL[plr2.Name]:remove()
        upd()
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

If I read your scripting correctly, you haven't actually acknowledged players that are in the game before you.

If you are using a localscript (you can still do this by finding the player through ScreenGui), use the following function:

    for _,plr in pairs(game.Players:GetPlayers()) do
        if plr ~= game.Players.LocalPlayer then
            -- your 'adding a player' script
        end
    end

^ The above may not be effective (I dunno), but gives you an example of what to do.

Call it when the LocalPlayer joins the game, and it will hopefully work.

If you require further assistance, just ask Good luck.

~~ Please upvote if I answered your question! ~~

Ad

Answer this question