So I made a DataStore script in and it did not work. Any fixes?
Faulty script 1:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore") game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" local cash = Instance.new("IntValue", stats) cash.Name = "Money" cash.Value = cash.Value + 100 local key = "player-"..player.userId local savedValues = DataStore:GetAsync(key) if savedValues then --Save format: {cash, coins} cash.Value = savedValues else local valuesToSave = {cash.Value} DataStore:SetAsync(key, valuesToSave) end end)
Faulty code 2:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore") game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId --Save key: {cash} local valuesToSave = {player.leaderstats.Money.Value} DataStore:SetAsync(key, valuesToSave) end)
You must use Start Server instead of Play Solo, otherwise Studio will not be able to use DataStores. Also, you must Enable API Access in Studio.