Alright, so I have been making a game recently and need to try to save a stat called BankedMoney located under the Player it is not in a leaderboard* it's a GUI. here is the code that I am trying to use if you could look over it and tell me where I went wrong that would be great!
local DataStore = game:GetService("DataStoreService"):GetDataStore("gameowner")
print("Money Leaderboard Working")
game.Players.PlayerAdded:connect(function(player)
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = player
local BankedMoney = Instance.new("IntValue")
BankedMoney.Name = "BankedMoney"
BankedMoney.Parent = player
local Key = "player-"..player.userid
local savedvalues = DataStore:getasync(Key)
if savedvalues then
BankedMoney.Value = savedvalues[1]
else
local valuestosave = {BankedMoney.value}
DataStore:setasync(Key, valuestosave)
end
end)
I also have a player leaving script for the DataStore
local DataStore = game:GetService("DataStoreService"):GetDataStore("gameowner")
game.Players.PlayerRemoving:connect(function(player)
local Key = "player-"..player.userid
local valuestosave = {player.BankedMoney.Value}
DataStore:setasync(Key, valuestosave)
end)

1 comment
@MrLonely1221 still won't work