My Cow Count wont update Milk

Hello I have a datastore table that has two values (along with a lot of others)
I made the variables

local Milk = Instance.new("IntValue", leaderstats)
	Milk.Name = "Milk"
	Milk.Parent = leaderstats

	local regularCow = Instance.new("IntValue", leaderstats)
	regularCow.Name = "regularCow"
	regularCow.Parent = leaderstats
playerData = {
				["Level"] = 1,
				["Exp"] = 30,
				["Gold"] = 55,
				["PKleaderboardexp"] = 10,	
				["regularCow"] = 3,
				["Milk"] = 3
			}

I store them in the table above, and then wrote a script to just add 10, but the datastore is no updating.
Here is the part that should add milk but doesn’t save stats or update after Heartbeat:Connect Fuction I setup to go off after 5 seconds (which is working).

local function giveMilkToPlayer(player)
	local milk = player.leaderstats.Milk.Value
	local cowCount = player.regularCow.Value
	local milkToAdd = cowCount
	milk = milk + cowCount
	
end

If I use the datastore GetAsync and SetAsync it will update, however I get throttling errors. What is going on as I do not understand datastores enough to access it from other scripts easily.

Possibly the issue is that you are trying to get the value “regularCow” in the player but is it not inside of the leaderstats not the player? Btw you can also just do += rather then adding the milk value onto cowCount (milk += cowCount).

You should only really be using datastores when a player joins and when a player leaves if possible to reduce the amount of times you need to use datastores.

1 Like

I think your right, I am taking a look at a few other things.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.