I am trying to make my script save the player's money value every 15 seconds.

It prints both that the data was saved, but when the player's money changes, it won't update it to save.

The game is published

here is my code:

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

game.Players.PlayerAdded:Connect(function(player)
	while wait(15)do
		local success, errorMessage = pcall(function()
			moneyDataStore:SetAsync(player.UserId.."-money", player.leaderstats.Money.Value) 
		end)

		if success then
			print("Player data successfully saved")
			print(player.leaderstats.Money.Value)
		else 
			warn(errorMessage)
		end
	end
end)

For example: When I joined the game, I updated my player's money from 0 to 100

in the output, it printed that my data was saved, but the value didn't change. It was still 0, even though in the leader stats board, it was 100.

If that doesn't make sense, here is the exact output messages: "Player data successfully saved" "0"

I hope I provided enough information about my problem, if you need more to be able to help me, please leave a comment.

Anything you think might help would greatly be appreciated!

Otherwise, have a great day, and thanks for stopping by!

6 comments

0

Did you change the value from the local side or server?

0

Was the game published?

0

Value was changed from the server side, the game is not published yet

0

You should publish it first, datastores typically don't work properly if it's unpublished. You can just make the game private while you test it.

0

It is published, it still does not work

0

Is there a function that changes your money.Value or no? That might be the cause.