My DataStore Doesn't save

i made a script for datastore that for the first 2 days it worked but now it doesn’t work idk if i changed something by mistake i tried to write again idk what to do
this is the script:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats

    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-cash")
    end)
    if success then
        cash.Value = data
    else
        print("player has no data")
        warn(errormessage) 
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value)
    end)

    if success then
        print("successsfully saved data")
    else
        print("data save failed")
        warn(errormessage)
    end
end)
2 Likes

Are you testing on studio or in-game?

Sometimes datstores don’t work on studio, I don’t know why, but test them in-game.

2 Likes

You can try to go to the Game Settings in Studio and activate, in Options , HTTP Service.

Also, you can try using DataStore2, it’s way better! :wink:

i tried always on studio i will try in-game

it’s actived and i’m not expert so if u can write me the script entirely

is there anything for your output?

it print successfully saved data

thx 30 charrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

then it totally works!

30charsssss

It works thx 30 charrrrrrrrrrrr