Money Value balance not showing/working

Heya! I wanted to make a value for make a money balance on my game for players, problem is that is not working, I want to display it on the playerlist of the game, the Script is on ServerScriptService and is like this:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local MoneyStore = DataStoreService:GetDataStore("MoneyStore")
local function saveMoney(player)
    local money = player:FindFirstChild("Euros")
    if money then
        MoneyStore:SetAsync(player.UserId, money.Value)
    end
end
local function loadMoney(player)
    local money = player:FindFirstChild("Euros")
    if money then
        local value = MoneyStore:GetAsync(player.UserId)
        if value then
            money.Value = value
        end
    end
end
local function giveEuros(player)
    local euros = player:FindFirstChild("Euros")
    if euros then
        euros.Value = euros.Value + 100
        saveMoney(player)
    else
        player:CreateFolder("Euros").Value = 100
        saveMoney(player)
    end
end
local function checkPlayers()
    for _, player in pairs(Players:GetPlayers()) do
        loadMoney(player)
        giveEuros(player)
    end
end
local function showMoney()
    local playerList = game:GetService("PlayerList")
    for _, player in pairs(playerList:GetPlayers()) do
        local money = player:FindFirstChild("Euros")
        if money then
            playerList:SetPlayerData(player, "Euros", money.Value)
        end
    end
end
while true do
    wait(5 * 60) -- 5 minutes
    checkPlayers()
    showMoney()
end

The idea is that the value (money) gives 100 to all players every 5 mintues, problem is that is not workign or even showing on the playerlist.
Also, then I want to show that balance on my PlayerUI located on StarterGUI. Here’s that script:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local MoneyStore = DataStoreService:GetDataStore("MoneyStore")
local function loadMoney()
	local player = Players.LocalPlayer
	local money = player:FindFirstChild("Euros")
	if money then
		local value = MoneyStore:GetAsync(player.UserId)
		if value then
			money.Value = value
		end
	end
end
local function showMoney()
	local player = Players.LocalPlayer
	local money = player:FindFirstChild("Euros")
	if money then
		local textLabel = game.StarterGui.ScreenGui.Frame.TextLabel
		textLabel.Text = "Euros: " .. money.Value
	end
end
while true do
	wait(5)
	showMoney()
end

Here’s startergui explorer screenshot for if needed:


“money display script” is the script where is created, saved, gived & loaded money, (euros) balance.
PlayerUI is the unique important ScreenGUI from StarterGUI, where Inside the open Frame, “User Balance” TextLabel is the label where i want to display the user’s balance. I would really appreciate any help!

2 Likes

First of all your money display script is in starter gui so you will have to put it in either ServerScriptService(preferable) or Workspace. Also I’m noticing that “Euros” is a Folder and can’t take a value so you can’t set its value to 100. Delete the folder and make a NumberValue with the name “Euros” and it will probably work.

1 Like

If you want to currency get displayed on leaderboard, you have to create folder inside player and you have to name it “leaderstats” with lowercase, and you have to put currency inside that folder if you want to get displayed on leaderboard, I don’t know why It’s like that but It sure works.

I’ll move the script of display to ServerScriptService anyways, could you write the script that you’re talking about?

All this on ServerScriptService?

This will break as Players.LocalPlayer doesn’t exist on server scripts. You should change this to a local script and remove DataStore load part as local scripts can’t access DataStores

Yeah.

Don’t do that, do what I said above

I don’t think Player:CreateFolder() and PlayerList exists. Try using Instance.new() instead.

    else
        euros = Instance.new("IntValue")
        euros.Name = "Euros"
        euros.Value = 100
        euros.Parent = player
        
        saveMoney(player)
    end