Help With Currency system

Okay, so we need to use DataStoreService and then :GetDataStore

We get a key for each player by using :GetAsync(player.UserId), which gets the player data when they join.

When a player leaves we save their data with :SetAsync(player.UserId, value)

If you want to go the extra mile you can make sure when roblox errors that player data isn’t lost with pcalls

So your script should look something like this when you are done:

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("IReallyLikeMoney")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new(“Folder”,player)
	folder.Name = “leaderstats”
	local currency1 = Instance.new(“IntValue”)
	currency1.Name = “Money”
	currency1.Parent = folder
	currency1.Value = DS:GetAsync(player.UserId) or 0

	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				if tag.Value ~= nil then
					currency1.Value = currency1.Value + 10 
				end 
			end
		end)
	 end) 
end)

game.Players.PlayerRemoving:Connect(function(player)
	DS:SetAsync(player.UserId, player.leaderstats.Money.Value)
end)

game:BindToClose(function()
	for _,v in pairs(game.Players:GetPlayers())do
		DS:SetAsync(v.UserId, v.leaderstats.Money.Value)
	end
end)

Let me know if you have any questions!

ya i have one question where do i put this ?

You take the code that I made and put it where your code is in ServerScriptService.

its giving me so many errors ?

It shouldn’t. Could you give me a list of the errors please?

Look where it has the " and retype it. Sometimes it errors with a copy and paste.

where im not seeing where that is

Dude, legit right in front of your face on line 5, 6, 7, 8, and 9.

that did not fix the problem it looks right

it fixed some of the problem but theres still some there now underlined

Show me another screen shot of the current script.

I said delete the " and retype it, there has been way to many replies for a simple answer.

ok I’m pretty sure i got it this time

Yep, you got it. Now you have to enable studio access to api services for it to work in studio, but when you publish it should work in game.

For the future PLEASE search for other topics like this in the future. There is literally a thousand other posts by searching here.

it still didnt work and i did everything you told me to do

On line 9 there should be no " around folder.

i dont see a no and if i need to put one i have no idea where to put it


simple, just remove the " around folder on line 9