What's wrong with my datastore script? I really have no idea :( Can someone please explain?
local DataStoreService = game:GetService("DataStoreService")
local DataStoring = DataStoreService:GetDataStore("DataStoring")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("IntValue", player)
leaderstats.Name = 'leaderstats'
local DRcoins = Instance.new("IntValue", leaderstats)
DRcoins.Name = 'DRcoins'
DRcoins.Value = 0
print("leaderstats generated")
local data
local success, errormessage = pcall(function()
data = DataStoring:GetAsync(player.UserId.. "-DRcoins")
end)
if success == true then
DRcoins.Value = data
else
print("There was an error in retrieving your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStoring:SetAsync(player.UserId.. "-DRcoins", player.leaderstats.DRcoins.Value)
end)
if success == true then
print("Playerdata succesfully saved")
else
print("Something went wrong with saving data")
warn(errormessage)
end
end)
the script^

5 comments
Just to clarify, you are testing this in-game and not in studio with API services enabled?
I published and tested using ROBLOX player, do you see any mistakes that I made in the script or so?
Do you have API services enabled in settings? - before i answer that (It's a common error)
Yes I have API services enabled for the game
I found out why.