Data Store Won’t Update In Roblox

I have been writing a script in Roblox that updates a players’ Money value in a folder inserted in leaderstats. Bascilly how everyone creates a leaderboard. The Money value is changed by a ProximityPrompt``Triggered``Event. It is first set off a data store script. I am very new to Data Store.

As I don’t know enough to try to fix this own my own nor able to read the API in the right context, anyhelp would be greatly appreciated. Here’s my code:

-- Money Update Script

local buttons = game.Workspace.buttons

-- Event Vars

-- Main Vars

local buy_railroad = buttons.buy_railroad.ProximityPrompt

local removeweeds1 = buttons.remove_weeds1.ProximityPrompt

local removeweeds2 = buttons.remove_weeds2.ProximityPrompt

-- Propertys

-- Action Vars

local weedremovemodel1 = workspace["weed remove1"]

local weedremovemodel2 = workspace["weed remove2"]

-- Misc Vars

local instructionsgui = buttons.buy_railroad.Part.BillboardGui.Frame

-- Logic

-- Functions

local function takemoneyfromplayers(player, money)
    local playertotake = game.Players:FindFirstChild(player)
    if playertotake then
        local lstats = playertotake:FindFirstChild("leaderstats")
        if lstats then
            local moneystat = lstats:FindFirstChild("Money")
            if moneystat and moneystat:IsA("IntValue") then
                moneystat.Value = moneystat.Value - money
            end
        end
    end
end

buy_railroad.Triggered:Connect(function(player)
    instructionsgui.Visible = false
    buy_railroad.Enabled = false
    buy_railroad.Parent.Transparency = 1
    removeweeds1.Enabled = true
    removeweeds1.Parent.Transparency = 0.7
    takemoneyfromplayers(player.Name,20000)
end)

removeweeds1.Triggered:Connect(function(player)
    removeweeds1.Enabled = false
    removeweeds1.Parent.Transparency = 1
    removeweeds2.Enabled = true
    removeweeds2.Parent.Transparency = 0.7
    takemoneyfromplayers(player.Name,400)
    for _, descendant in pairs(weedremovemodel1:GetDescendants()) do
        if descendant:IsA("BasePart") or descendant:IsA("MeshPart") then
            descendant.CanCollide = false
            for transparency = 0.2, 1, 0.1 do
                if transparency < 1 then
                    descendant.Transparency = transparency
                    task.wait(0.01)
                else
                    break
                end
            end
        end
    end
end)

removeweeds2.Triggered:Connect(function(player)
    removeweeds2.Enabled = false
    removeweeds2.Parent.Transparency = 1
    takemoneyfromplayers(player.Name,400)
    for _, descendant in pairs(weedremovemodel2:GetDescendants()) do
        if descendant:IsA("BasePart") or descendant:IsA("MeshPart") then
            descendant.CanCollide = false
            for transparency = 0.2, 1, 0.1 do
                if transparency < 1 then
                    descendant.Transparency = transparency
                    task.wait(0.01)
                else
                    break
                end
            end
        end
    end
end)
--Data Store Script
local DSS=game:GetService("DataStoreService")
local mainDS=DSS:GetDataStore("Money")
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local Events=ReplicatedStorage:FindFirstChild("Events")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats=Instance.new("Folder",player)
    leaderstats.Name="leaderstats"
    local money=Instance.new("IntValue",leaderstats)
    money.Name="Money"
    local data=mainDS:GetAsync(player.UserId)
    if data then
        if data[1] then
            money.Value=data[1]
        else
            money.Value=20000
        end
    end
    
    money.Changed:Connect(function()
        mainDS:SetAsync(player.UserId, {money.Value})
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local leaderstats=player:WaitForChild("leaderstats")
    local money=leaderstats:WaitForChild("Money")
    mainDS:SetAsync(player.UserId,{money.Value})
end)

I expect the data to save once i exit the game, but it doesn’t. It appeers to on the leaderboard, but after in the money script when Itake money away, it defults to the data store. I am sure of this due to printing the data store with the User’s ID and the correct key, "Money" and then printing it with a seperate script. It prints a dictionary with an empty Instance.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật