Trying to store PlayerGui.Menu.Stats.Z.Money.Text
localScript position = game.Players.LocalPlayer.PlayerGui.Menu.Stats.Z.Money.LocalScript
local money = script.Parent:WaitForChild("Money") local Gui = script.Parent money.Changed:connect(function() Gui.Text = money.Value end)
ServerScriptService
local dataStore = game:GetService("DataStoreService"):GetDataStore("Money") function SaveData(dataname, playerid, value) dataStore:SetAsync(playerid, value) print(playerid) print(value) end game.Players.PlayerAdded:connect(function(player) local money = player.PlayerGui:WaitForChild("Menu").Stats.Z.Money["Money"] money.Value = dataStore:GetAsync(player.userId) money.Changed:connect(function() SaveData("Money", player.userId, money.Value) wait(1) SaveData("Money", player.userId, money.Value) end) end)
If you want to save your currency into the datastore, I suggest that you use an IntValue or NumberValue and put in the LocalPlayer. Here's the code to create it :
Creating Currency (ServerScript) :
-- Example code only change what you want. local dataStore = game:GetService("DataStoreService") local moneyData = game:GetService("DataStoreService"):GetDataStore("Money") function SaveData(dataname, playerid, value) dataStore:GetDataStore(dataname):SetAsync(playerid, value) end game.Players.PlayerAdded:connect(function(player) -- Optional you can put in outside of leaderstats too local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = player -- You can also change the money.Parent to "player" (No double quotes) local money = Instance.new("IntValue") money.Name = "Money" money.Value = moneyData:GetAsync(tostring(player.userId)) or 350 money.Parent = stats while true do wait(.5) money.Changed:connect(function() SaveData("Money", player.userId, money.Value) end) end end) game.Players.PlayerRemoving:connect(function(player) SaveData("Money", player.userId, player.leaderstats.Money.Value) end)
With this you can only edit the values in-game.
Putting the currency into the gui (LocalScript) :
-- Example code only change what you want. local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local mainGui = playerGui:WaitForChild("MainGui") local stat = game.Players.LocalPlayer:WaitForChild("leaderstats") local money = stat:WaitForChild("Money") local moneyGui = script.Parent.Money moneyGui.Text = "$" .. money.Value money.Changed:connect(function() desiredMoney.Value = money.Value end)
Sorry that I don't use RemoteEvents or RemoteFunction for this method.