Why isn't my player data save working?

ok, but i really think there is something wrong with my roblox studio, i will edit the script and everything, and restart my roblox studio

Hey. I tested your script. And it doesnt seem to be anything wrong. Try restarting your studio??

Also. Are you changing the value of the coins on the ServerSide. Or the client??

Datastore doesn’t work on the client(Correct me) plus it’s not safe anyway.

ok, yes i think there is something wrong with my roblox studio

it gives me so many errors when i try to publish the game

Oh yeah that happened to me once. What does the error say?

in the console, it displays this right after i publish the game, and it has a much longer thing, but here is one example and it repeats a LONG time:
builtin_PublishPlaceAs.rbxm.PublishPlaceAs.Packages._Index.Roact-e3b370a8-ec68e60e.Packages.Roact.createReconciler:108 function updateVirtualNodeWithRenderResult

Are you using team create or something?

and then it says
13:11:21.925 Could not publish configuration settings. - Studio
13:11:21.925 HTTP 400 (Bad Request) - Studio

and no i am not using team create

Have youu tried restarting your pc?

no, but i will, i’ll be back in like, 5 minutes

Services are working properly, let’s wait if there’s anything new.

I noticed that you’re not using pcall() when you do :GetAsync().

i am not using that script anymore, i am using Mysterious_Myth11’s script

for some reason it is still not working

hey, umm, it is still not work, idk what to do

local dataStore = game:GetService("DataStoreService")
local playerData = dataStore:GetDataStore("playerData")


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

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


     local coins = Instance.new("IntValue")
     coins.Name = "Coins"
     coins.Parent = leaderstats

     local DataStoreKey = "Player: " .. player.UserId
     local Data
     local Success, Error = pcall(function()
        Data = playerData:GetAsync(DataStoreKey)
    end)

     if Success then
         coins.Value = Data
     else
         print("Datastore Error: Getting data error. \n ", Error)
     end
end)


game.Players.PlayerRemoving:Connect(function(player)
     local DataStoreKey = "Player: " .. player.UserId
     local Success, Error = pcall(function()
        playerData:SetAsync(DataStoreKey, player.leaderstats.Coins.Value)
     end)

    if Success then
        print("Successfully saved data")
    else
        warn("Datastore Error: Saving data error. \n ", Error)
    end
end)

Test it.

1 Like

thanks dude so much, i will test it

ok, this script works, and i think all the other did too, but the issue is the thing that gets me coins, i do not think that coin adder script works, here is the script

script.Parent.MouseButton1Click:Connect(function(click)
	game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Coins.Value + 1

end)

it is a button btw in case u needed to know