I have a DataStore2 leaderboard (shown below) and I want to get the value of the players coins and show it on screen with a textbox.
I did it before but I haven’t been on roblox studio in a long time.
Anyone can help out?
leaderboard script in ServerScriptService
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local DataStore2 = require(ServerScriptService.DataStore2)
-- Combine every key you use. This will eventually be the default, but for now read the "Gotchas" section to understand why we need this.
DataStore2.Combine("DATA", "Wins", "Coins")
Players.PlayerAdded:Connect(function(player)
local winsScore = DataStore2("Wins", player)
local coinsScore = DataStore2("Coins", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local Wins = Instance.new("NumberValue")
Wins.Name = "Wins"
Wins.Value = winsScore:Get(0)
Wins.Parent = leaderstats
winsScore:OnUpdate(function(newWins)
Wins.Value = newWins
end)
local Coins = Instance.new("NumberValue")
Coins.Name = "Coins"
Coins.Value = coinsScore:Get(0)
Coins.Parent = leaderstats
coinsScore:OnUpdate(function(newCoins)
Coins.Value = newCoins
end)
leaderstats.Parent = player
end)
LocalScript inside textbox in StarterGui
local textbox = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local DataStore2 = require(game.ServerScriptService.DataStore2)
local winsScore = DataStore2("Wins", player)
local coinsScore = DataStore2("Coins", player)
while wait() do
textbox.Text = coinsScore:Get(0)
end