****so i have this script and i tried changing the value of the leaderstats R-Bucks in game, and i did. But when i rejoined it reset me to the default 50 R-Bucks.
local currencyName = "R-Bucks"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("data has been loaded")
else
currency.Value = 50
print("New player has entered")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("Server being shutdown.")
end
end
wait(5)
end)
``

1 comment
i played in studio with that script, set the value to 999, rejoined and it was 0, so it didnt even set me to default value of 50