Leaderstats Isn't Loading in when the Player joins
07:31 20 Nov 2023

I have made a leaderstats script with 2 Folders and 6 stats. when i test the game none of the stats are loading in. Here is the script:

local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
local DataStore2 = game:GetService("DataStoreService"):GetDataStore("ValueSave2")
local DataStore3 = game:GetService("DataStoreService"):GetDataStore("ValueSave3")
local DataStore4 = game:GetService("DataStoreService"):GetDataStore("ValueSave4")
local DataStore5 = game:GetService("DataStoreService"):GetDataStore("ValueSave5")
local DataStore6 = game:GetService("DataStoreService"):GetDataStore("ValueSave6")

game.Players.PlayerAdded:Connect(function(plr)


    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"

    local plrstats = Instance.new("Folder", plr)
    plrstats.Name = "Multipliers"

    local cash = Instance.new("IntValue", leaderstats)
    cash.Name = "Jump"
    cash.Value = DataStore:GetAsync(plr.UserId) or 1
    
    local cash1 = Instance.new("IntValue", leaderstats)
    cash.Name = "Run"
    cash.Value = DataStore5:GetAsync(plr.UserId) or 1
    
    local cash2 = Instance.new("IntValue", leaderstats)
    cash.Name = "Climb"
    cash.Value = DataStore6:GetAsync(plr.UserId) or 1

    local Upgrade = Instance.new("IntValue", plrstats)
    Upgrade.Name = "ClimbMultiplier"
    Upgrade.Value = DataStore4:GetAsync(plr.UserId) or 1
    
    local multi = Instance.new("IntValue", plrstats)
    multi.Name = "RunMultiplier"
    multi.Value = DataStore2:GetAsync(plr.UserId) or 1

    local cost = Instance.new("IntValue", plrstats)
    cost.Name = "JumpMultiplier"
    cost.Value = DataStore3:GetAsync(plr.UserId) or 1

    cash.Changed:Connect(function()
        DataStore:SetAsync(plr.UserId, cash.Value)
    end)

    Upgrade.Changed:Connect(function()
        DataStore4:SetAsync(plr.UserId, Upgrade.Value)
    end)

    cost.Changed:Connect(function()
        DataStore3:SetAsync(plr.UserId, cost.Value)
    end)
    
    multi.Changed:Connect(function()
        DataStore2:SetAsync(plr.UserId, multi.Value)
    end)
    
    cash1.Changed:Connect(function()
        DataStore5:SetAsync(plr.UserId, cash1.Value)
    end)
    
    cash2.Changed:Connect(function()
        DataStore6:SetAsync(plr.UserId, cash2.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    DataStore:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
    DataStore4:SetAsync(plr.UserId, plr.Multipliers.Upgrade.Value)
    DataStore3:SetAsync(plr.UserId, plr.Multipliers.Cost.Value)
    DataStore2:SetAsync(plr.UserId, plr.Multipliers.multi.Value)
    DataStore5:SetAsync(plr.UserId, plr.leaderstats.cash1.Value)
    DataStore6:SetAsync(plr.UserId, plr.leaderstats.cash2.Value)
end)

After I join, there is no error in the output. What is wrong with this script? What can I do to fix it? Please help.

I needed to add these words to post my problem.

lua roblox