pls help! everytime i try to add more values the script ends up glitchy and unresponsive. If u know why this is happening pls tell me.
local DataStore = game:GetService("DataStoreService")
local Ds1 = DataStore:GetDataStore("DS")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue",player)
stats.Name = "leaderstat"
local gold = Instance.new("IntValue",stats)
gold.Name = "Gold"
gold.Value = Ds1:GetAsync(player.UserId) or 100
Ds1:GetAsync(player.UserId, gold.Value)
end)
game.Players.PlayerRemoving:connect(function(player)
print("Saving Data")
Ds1:SetAsync(player.UserId, player.leaderstat.Gold.Value)
print(player.Name.."'s Data Saved")
end)

1 comment
use a table to save and load all the values at once.