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!