My DataStore doesn't work

Oops, I forgot to parent the leaderstats in that example code. insert it in between here:

leaderstats.Name = "leaderstats"
leaderstats.Parent = plr -- insert it in between these other lines of code
local cash = Instance.new("IntValue")

Here is the fixed code:

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("DataStore")
local defaultCash = 50 -- change amount to your liking

game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr
    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats

    local data
    local success, message = pcall(function()
        data = dataStore:GetAsync(plr.UserId.."-cash")
    end
    if success then
        if data then
            cash.Value = data
        else
            print(plr.Name.." is a new player")
            cash.Value = defaultCash
        end
    else
        warn(message)
    end
end

game.Players.PlayerRemoving:Connect(function(plr)
    local data = plr.leaderstats.Cash.Value
    local success, message = pcall(function()
        dataStore:SetAsync(plr.UserId.."-cash", data)
    end
    if success then
        print("data for "..plr.Name.." saved")
    else
        warn(message)
    end
end

well it works as the same as @EHGTR1903

This part of the script is flawed, you’ll want to use my example code because it will work better.

Ok but now we have to save it (30 charrrrr)

My example code saves the data as well

That part is just to check if it’s loading the datastore or not. I already said that here

yeah it’s for this i said but now we need to save

no everytime i join the value will be 50