Hi, when the player joins the game, the player can see their currency value. If the player dies in-game, it defaults the GUI text. Here is the code
PlayerDatastore2
local DataStore2 = require(game.ServerScriptService.DataStore2)
local defaultCashValue = 0
game.Players.PlayerAdded:Connect(function(plr)
local coinsDataStore = DataStore2("Coins", plr)
local cash = Instance.new("IntValue")
cash.Name = "Cash"
local function coinsUpdated(updatedValue)
cash.Value = coinsDataStore:Get(updatedValue)
game.ReplicatedStorage.UpdateClientCurrency:FireClient(plr, coinsDataStore:Get(defaultCashValue))
end
coinsUpdated(defaultCashValue)
coinsDataStore:OnUpdate(coinsUpdated)
end)
GUI Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.UpdateClientCurrency.OnClientEvent:Connect(function(updatedValue)
script.Parent.Text = "$" .. updatedValue
end)
Thanks for the help!