I have been trying to learn data store from many articles and tutorials. I always follow along, remember to switch on HTTP services for studio, and write everything exactly as they tell me to. Though when they get a saved result, I don't. I've tried putting print statements in my code, and I've found that it skips the Get and Set Async lines. Any help would be greatly appriciated.
DataService = game:GetService("DataStoreService")
DataStore = DataService:GetDataStore("DataStore1")
game.Players.PlayerAdded:Connect(function(player)
print("player joined")
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
print("leaderstats made")
local Credits = Instance.new("IntValue", leaderstats)
Credits.Name = "Credits"
print("credits made")
local PlayerId = "id_"..player.UserId
print("id achieved")
--// Loading data
local data
print("made data variable")
local success, errormessage = pcall(function()
print("entered first pcall")
data = DataStore:GetAsync(PlayerId)
print("gotten data")
end)
if success then
Credits.Value = data
else
print("something went wrong when loading")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
print("player left")
local PlayerId = "id_"..player.UserId
print("loaded id")
--// Saving data
local success, errormessage = pcall(function()
print("entering pcall")
wait()
DataStore:SetAsync(PlayerId, player.leaderstats.Credits.Value)
print("saved")
end)
if success then
print("data saved wohoo")
else
print("data not saved oh no")
warn(errormessage)
end
end)
