My DataStore wont let me add Starter Cash

So basically I am making a Cash system with datastores (like most anyone would do) and I have come to an issue. I have tried to add a value that adds starting cash if the player has never joined before. I followed another tutorial by adding “cash.Value = 20000” to try to add 20k into the default starting money.

The issue is that when I join the game it does not give me the starting cash, I have looked through the console for errors and there is none, I have also used a datastore editor which also says it is at 0.

Here is my code when the player joins with the datastore editor showing that I have “nil” in the datastore editor.

Here is in game showing I have no cash and that my other script which is local that checks how much money you have and shows it in console.

Any solutions will help!

2 Likes

are you trying to do this in studio? or on the roblox player

2 Likes

When success is true it means the datastore API call didn’t fail, not that data exists. If you check other datastore scripts, you will notice those are 2 different cases, but in your case, they can be combined as one:

if success and data then
	cash.Value = data
elseif not success then
	warn(errorMessage)
else
	print("No data!")
end

Basically success == true means there was no datastore error and data ~= nil means that data exists.

3 Likes

thanks you so much!!!

2 Likes

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