How to add credits/money to someone's leaderstats on the first time they join?

I want to be able to add the person 500k Credits when they join the game for the first time.
Right now I have a script that saves both leaderstats, however I want the person to start out with 500k credits.

If I set it that the user always has 500k, then every time they join the game they’re going to reset to 500k credits again.

Essentially I need a way to check if a person is joining for the first time, and if so, add them 500k to their Credits.

Any help is appreciated, thank you!

Then your going to have to user DataStore to save a value called like hasJoined, and if its there first time joining make hasJoined true and then when you give players credits when they first join just check if they have joined already

Use BoolValues(I guess?). Like, make a boolvalue called “Claimed500k” and when the user joins the game, check if the value of this is set to false. If so, give the user his/her 500k, and set the value to true and save this through a datastore. You don’t really have to use boolvalues though, you can simply use datastores as “IProgramForFun” said, depends on your choice.

Also use datastore2 it helps you save so easily since this is a dictionary
I also recommend you use this data structure for keeping player data organized

_G.Data = {}

game.Players.PlayerAdded:Connect(function(player)
	_G.Data[player.UserId]["hasJoined"] = false
    _G.Data[player.UserId]["Credits"] = 0
	
	-- new player
	if not _G.Data[player.UserId]["hasJoined"] then
		-- award credits
	else
		-- not a new player
	end
	
end)
2 Likes

You can use DataStores to check if a player already has saved data or not, if they don’t then you can give them 500k Credits when they first start out

You can also refer to this API:

Thank you for that.

So I just need to put in the line to add credits and I should be good to go?

Well youll obviously need to setup datastore2 but its not that hard, and also youll need to refer to the datastore value of the dictionary

Sorry if thats confusing, just search up how to save a dictionary with datstore2 and youll be all set,

You can save really easily with this kind of structure

If you want to add more stuff to save just put it inside of the _G.Data[player.UserId] = {} table and youll be all set