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)

1 comment
I did start a server, and also enabled the API access in studio, but it doesn't work.