What do you want to achieve? I want to make a custom leaderstats gui with the list of players with the amount of cash/points the player has. And I just want to make it mobile friendly(mobile players can’t see leaderstats.)
What is the issue? None, actually, I just want to make a gui with a list of players and amount of the player’s cash.
What solutions have you tried so far? Tried to look on YouTube but no one makes tutorials on my problem.
Edit: Here’s the script:
Leaderstats:
local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Bucks = Instance.new("IntValue", leaderstats)
Bucks.Name = "Bucks"
Bucks.Value = DataStore:GetAsync(plr.userId) or 0
Bucks.Changed:Connect(function()
DataStore:SetAsync(plr.userId, Bucks.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
DataStore:SetAsync(plr.userId, plr.leaderstats.Bucks.Value)
end)
Just add a GUI then put a local script in it. The script would look like this: (BTW the script in this situation is inside of the text label being changed.)
plr = game.Players.LocalPlayer
stat = Cash
while wait(0.1) do
script.Parent.Text = "Cash: "..plr.leaderstats[stat].Value
end
EDIT: I didn’t read the entire thing, this is just a script that tells the player what their stats are not like a custom leaderboard, that’s too advanced for me.
If I’m understanding correctly, the previous replies are wrong. If you want to get the leaderstats of each player, you can iterate through Players:GetPlayers() and create a GetPropertyChangedSignal event for each of them.
Here’s what the iteration would look like, but make sure to update this when a player joins/leaves as well.
for _, plr in pairs (game:GetService("Players"):GetPlayers() do
local leaderstats = plr:WaitForChild("leaderstats", 1)
if leaderstats then
local frame = template:Clone() -- Template would be an invisible frame that is a template for a slot on your leaderboard. You can organize them easily using a UIGridLayout.
frame.Username.Text = plr.Name
frame.Stat.Text = leaderstats.Cash.Value
frame.Visible = true
frame.Parent = template.Parent
leaderstats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
frame.Stat.Text = leaderstats.Cash.Value
end)
end
end
I don’t think there would be a need to perform manual garbage collection for the GetPropertyChangedSignal event because it would automatically be disconnected when the player leaves (therefore the frame would be destroyed with the PlayerRemoving event that you’ll add), but I could be wrong.