I have enabled studio access to API services. I also have this script in the server script service to save my coins. But it doesn't. What's wrong?
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0
-- Data Store Section
local playerUserId = "Player_"..player.UserId
print(playerUserId)
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
coins.Value = data
if success then
coins.Value = data
-- Set our data equal to the current Coins
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = player.leaderstats.Coins.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error saving the data!")
warn(errormessage)
end
end)

1 comment
Does it print "Data successfully saved!" or "There was an error saving the data!" when you leave?