Hey, I’ll make it quick and simple. I don’t know if my DataStore is actually working. The script fires normally without any issue, no warnings or fails. But It doesn’t save my data. I don’t even know if it would load it either; but that’ll be a different post if it has to be.
Below is part of the script that handles when the player leaves and the save data should save. I can also add when the player is added. For privacy reasons I can’t show the whole script but I can show as much as I can
Any help or insight is appreciated
...
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return database:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait(3)
end
until success or attempt == 5
if success then
print("Connected Successfully. Saving...")
if not playerData then
print("Failed to Connect to Roblox DataStore and Save Data Services. Contact Banoi.")
playerData = {
["Cash"] = 500,
["Nails"] = 0,
["Wire"] = 0,
["Electronics"] = 0,
["Cellphone"] = 0,
["Soap"] = 0,
["Empty"] = 0
}
end
sessionData[player.UserId] = playerData
else
warn("Unable to fetch player data for;",player.UserId," - We are sorry. Please contact Banoi.")
player:Kick("We are unable to load your data. Please reconnect or contact Banoi. We are sorry for this inconvenience!")
end
wait(1)
-----------------------
leaderstats.Parent = player
if ResetStatsFunct == true then
print("Stats are Resetting; reset is true. True either by Manual Activation or Server Error")
wait(5)
item_Nails.Value = 0
item_Wire.Value = 0
item_ElectricScrap.Value = 0
item_Cellphone.Value = 0
item_Soap.Value = 0
ResetStatsFunct = false
else
print("Stats are safe; reset is false.")
end
end
Players.PlayerAdded:Connect(PlayerAdded)
function PlayerLeaving(player)
if sessionData[player.UserId] then
local success = nil
local errMSG = nil
local attempt = 1
repeat
success, errMSG = pcall(function()
database:SetAsync(player.UserId, sessionData[player.UserId])
end)
attempt += 1
if not success then
warn(errMSG)
task.wait(3)
end
until success or attempt == 5
if success then
print("Data stored under the User: ", player.Name, " has been aquirred.")
else
warn("Unable to save for the User: ", player.Name)
end
end
print(player,"Left the game. See you soon!")
task.wait(1)
end -- This end is connected to when the player enters the game. Its not loose.
Players.PlayerRemoving:Connect(PlayerLeaving)