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

[Solved] How do you make a custom leaderboard?

Asked by 4 years ago
Edited 4 years ago
local players = game:GetService('Players')
TextButton = script.Parent.TextButton
Difference = 0

function UpdateList()
for _,Button in pairs(script.Parent:WaitForChild("Frame"):GetChildren())
    do
        Difference = 0
        Button:Destroy()
    end
-- Clear all Names.
    for _,plr in ipairs(players:GetPlayers()) do
        local Clone = TextButton:Clone()
        Clone.Position = UDim2.new({0.018, 0},{0.036+Difference, 0})
        Clone.Visible = true
        Difference = Difference + 0.1
        Clone.Text = plr.Name
    end
end

players.PlayerAdded:Connect(UpdateList)
players.PlayerRemoving:Connect(UpdateList)

Well, the code above doesn't work as intended, and I tried for soooo long to get this to work. I tried doing it on the client, the server, but nothing worked. I wish I could just get this one problem out of the way, so I can finally work on my game efficiently.

If you know what to do/have done this before I would be very thankful if you helped me. I don't think a normal answer will suffice, as new problems keep arising. Therefore, it would be very nice if you could communicate with me and help me solve this issue.

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I'm not very good at coding and I definitely don't understand your script... but I do know how to make a 'custom' leader board. Hopefully this helps... Anyways, you probably want to be using something called UIListLayout. I see you are trying to manually do some positioning but this would make it easier. You put it in a frame and it will automatically list things in the correct positions. Also note if you are trying to but the highest value at the top you can definitely do that with UIListLayout. You may have to adjust the padding but that is it. The way I used it is by have a frame with different text labels to display the players information in replicated storage and just copied it into the frame with the UIListLayout. Then you just add/remove the frame with their values when a player joins/leaves. I'm not really sure what your trying to do with that script and I would be able to elaborate on what I did more if you want. I also hope this points you into the correct direction and help you get closer to your goal.

0
One question: Do you put the Frames inside the ListUI or inside the object that is the parent of the ListUI? User#34929 0 — 4y
0
Ok nvm i figured it out myself User#34929 0 — 4y
1
The parent. ASimpleGalaxy 36 — 4y
1
I can't thank you enough! User#34929 0 — 4y
1
I'm so happy I could help you! ASimpleGalaxy 36 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

I wrote a script that includes an optional cash value.

Server


local function update(player,Cash) game.ReplicatedStorage.UpdateCount:FireAllClients(player,Cash.Value) game.StarterGui.LeaderboardGUI.Frame.ScrollingFrame:FindFirstChild(player.Name).Cash.Text = Cash.Value end game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Cash = Instance.new("IntValue") Cash.Parent = leaderstats Cash.Name = "Cash" if player.Name == "TheWaildug" then Cash.Value = 1000 end game.ReplicatedStorage.AddPlayer:FireAllClients(player) wait(10) local Clone = game.ReplicatedStorage.Player:Clone() Clone.Parent = game.StarterGui.LeaderboardGUI.Frame.ScrollingFrame Clone.PlayerName.Text = player.Name Clone.Cash.Text = Cash.Value Clone.Name = player.Name while wait() do Cash:GetPropertyChangedSignal("Value"):Connect(function() update(player,Cash) end) end end) game.Players.PlayerRemoving:Connect(function(player) game.ReplicatedStorage.RemovePlayer:FireAllClients(player) end) game.ReplicatedStorage:WaitForChild("PlayerHasCash").OnServerInvoke = function(player) local Leaderstats = player:WaitForChild("leaderstats") local Cash = Leaderstats:WaitForChild("Cash") return Cash.Value end

Client


game.ReplicatedStorage.AddPlayer.OnClientEvent:Connect(function(player) if not script.Parent:FindFirstChild(player.Name) then print(player.Name) local T = game.ReplicatedStorage.Player:Clone() T.Name = player.Name T.PlayerName.Text = player.Name local Cash = game.ReplicatedStorage.PlayerHasCash:InvokeServer(player) print(Cash) T.Cash.Text = Cash T.Parent = script.Parent end end) game.ReplicatedStorage.RemovePlayer.OnClientEvent:Connect(function(player) if script.Parent:FindFirstChild(player.Name) then script.Parent[player.Name]:Destroy() end end) game.ReplicatedStorage.UpdateCount.OnClientEvent:Connect(function(player,amount) if script.Parent:FindFirstChild(player.Name) then script.Parent[player.Name].Cash.Text = amount end end)

Here is a completed model of it.

1
Thanks for the effort! User#34929 0 — 4y

Answer this question