Hello I would like to know how I can make each player see their money in their ‘gui’, how can I do that?
In short, I need to show the same cash value that is on the leaderboard and in the gui of each local player, how could i do that? could someone help me, please…
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error with getting your data.")
wait(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value)
end)
if success then
print("Player data successfully saved!")
else
print("There was an error when saving data.")
warn(errormessage)
end
end)
In a local script that is a child of the textlabel. Sorry I had a few typos so if it doesn’t work recopy it.
local player = game.Players.LocalPlayer --define player
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash") --define cash
cash.Changed:Connect(function() --whenever cash changes
script.Parent.Text = "Cash: "..cash.Value --set text
end)
local textlabel = --path to the text label
local player = game:GetService("Players").LocalPlayer
local stats = player:WaitForChild("leaderstats")
local value = stats and stats:WaitForChild("Cash")
if (value) then
value.Changed:Connect(function()
textlabel.Text = "Coins: $"..value.Value
end)
else
warn("stats not loaded")
end
You need to make sure you are actually pointing to the TextLabel.
Try changing the script.Parent.Text = ... to script.Parent.TextLabel.Text = ...
If you have the script in the ScreenGui.