I've tried looking online, youtube tutorials, etc. but none of the ones I found worked.
Here's one of the codes that I made, similar to the online ones.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("BucksStats")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local Bucks = Instance.new("StringValue")
Bucks.Name = "Bucks"
Bucks.Parent = leaderstats
Bucks.Value = DataStore:GetAsync(player.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(player) DataStore:SetAsync(player.UserId, player.leaderstats.Bucks.Value) end)
I used a regular (not module or local script) in ServerScriptService. Tested it, did the command :change OmegaNuker Cash 2, then rejoined the game, but I then had 0 Cash. I was expecting it to be 2 cash, but it didn't work that way.

4 comments
It works when i tried it
Make sure that the game has dataStore turned on and it is published, otherwise it won't work, also i think it should be public but not sure.. Also if you changed the value on the client and not on the server it won't work too because it is only on the client and data store saves on the server.
Basically he's saying, publish the game, go to settings and make sure you enable API services such as Datastores.
Thanks, that helped and it works now.