Need help displaying the value of coins on a textlabel

i want to display the coins value onto a textlabel
im using profile service so i dont know how to do it and cant find any tutorials that work

local PlayerDataHandler = {}

local dataTemplate = {
	Coins = 0,
	Gems = 0,
	Pets = {}
}

local ProfileService = require(game.ServerScriptService.Libs.ProfileService)
local Players = game:GetService("Players")

local ProfileStore = ProfileService.GetProfileStore("Data", dataTemplate)

local Profiles = {}

local function playerAdded(player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	
	if profile then
		profile:AddUserId(player.UserId)
		profile:Reconcile()
		
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick()
		end)
		
		if not player:IsDescendantOf(Players) then
			profile:Release()
		else
			Profiles[player] = profile
			print(Profiles[player].Data)
		end
	else
		player:Kick()
	end
end

function PlayerDataHandler:Init()
	for _, player in game.Players:GetPlayers() do
		task.spawn(playerAdded, player)
	end
	
	game.Players.PlayerAdded:Connect(playerAdded)
	game.Players.PlayerRemoving:Connect(function(player)
		if Profiles[player] then
			Profiles[player]:Release()
		end
	end)
end

local function getProfile(player)
	assert(Profiles[player], string.format("Profile does not exist for", player.UserId))
	return Profiles[player]
end

function PlayerDataHandler:Get(player, key)
	local profile = getProfile(player)
	assert(profile.Data[key], string.format("data does not exist for key",key))
	return profile.Data[key]
end

function PlayerDataHandler:Set(player, key, value)
	local profile = getProfile(player)
	
	assert(profile.Data[key], string.format("Data does not exist for key ", key))
	assert(type(profile.Data[key]) == type(value))
		
	profile.Data[key] = value
		
end

function PlayerDataHandler:Update(player, key, callback)
	local profile = getProfile(player)
	
	local oldData = self:Get(player, key)
	local newData = callback(oldData)
	
	self:Set(player, key, newData)
	
end




return PlayerDataHandler

If I understand correctly, I think you should add a simple local script inside your text label:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local label = script.Parent

label.Text = player.leaderstats.Coins.Value

player.leaderstats.Coins.Changed:Connect(function()
	label.Text = player.leaderstats.Coins.Value
end)

how do i make a leaderstats folder and update the numbervalue to the coins value with profile service

Search around the devforum and Youtube for tutorials on how to make saving leaderstats. Here is what a leaderstats script WITHOUT saving would look like:

game.Players.PlayerAdded:Connect(function(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Parent = player
	Coins.Value = 0
	
end)

Of course you would need to add saving and as far as updating the integer value you could run this.

[IntValueLocation].Value += (amount to add) --to add a certain amount of coins to their account

and to set the value of their coins…

[IntValueLocation].Value = (amount to set)

I almost never worked with Profile Service, but if you got a way to get the data from Profile Service, such as: Coins, Gems, etc, follow the next instructions:

Create a server script inside ServerScriptService and call it whatever you want.

Copy this code:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats
end)

And then, in your Profile Service script, get the player and search for the “Coins” NumberValue inside the “leaderstats” Folder in the Player.

Hope this helped!

Edit: Again, I never worked with Profile Service, so im just being general.

You shouldn’t use NumberValue as it gives a decimal point (e.g. 3.14159) and is less efficient for leaderstats. Instead you should try using IntValue as it gives an integer (e.g. 3)

1 Like

Oh, thank you, I honestly didn’t know that since i though IntValue and NumberValue were the same, again, thanks.

1 Like

what? all i asked is how to set the text not how to make leaderstats

and yes i know that i asked how to make a leaderstats but i also mentioned how do i do it with profile service

I did mention that and by stating how to make leaderstats, I also stated how to change the value of coins! I did not know that you needed it for a textlabel so that is my complete fault.

If you would still like help on it, you can run a script inside the textlabel and use the
.Changed function on the value. When it is changed you can then run the function and set the value of it to the integer!

Hope this helps!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.