Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get my data store to update when the money changes?

Ok, I am trying to make the money that the player gets save so that when they next come on the game they keep their money. However it does not seem to be working. It saves the 100 that I have set to be default. But when the money gets updated, it doesn't update the service. I don't know if I'm saying this right, but that's what I am understanding from it.I don't know if I'm saying this right, but that's what I am understanding from it. So here is my code:

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

game.Players.PlayerAdded:Connect(function(player)	
	print("Player Added!")
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local money = Instance.new("IntValue", leaderstats)
	money.Name = "Money"
	wait(10)
	print("Getting Player's Money! They have: "..MoneyStore:GetAsync(player.UserId))
	money.Value = MoneyStore:GetAsync(player.UserId) or 100
	MoneyStore:SetAsync(player.UserId, money.Value)
	money.Changed:Connect(function()
		print("Player's Money has been changed! Amount: ".. MoneyStore:GetAsync(player.UserId))
		MoneyStore:SetAsync(player.UserId, money.Value)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	print("Player Left! ".."Saving Money!")
	MoneyStore:SetAsync(player.UserId, player.leaderstats.Money.Value)
	print("Amount of money saved: ".. MoneyStore:GetAsync(player.UserId))
end)

2 answers

Have you enabled API's in your game?

Configure Game > Enable Studio Access to API Services: [X]

1 comment

0

i have, because i have another data store working

This discussion is preserved as it was. New answers, comments, and votes are closed.