Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i set a default value in leaderstats WITH a datastore?

Asked by 3 years ago

Hi! So I got a script to save my leaderstats but I don't have a default value set and I want the default value to be set for new players. Here is my script:

local ds = game:GetService("DataStoreService")
local dss = ds:GetDataStore("CoolDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local stage = Instance.new("IntValue")
    stage.Name = "Stage"
    stage.Parent = leaderstats


    local data 
    local success, errormessage = pcall(function()
        data = dss:GetAsync(player.UserId.."-stageNumber") 
    end)
    if success then 
        stage.Value = data
            print("kool aid somebody loaded data")
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        dss:SetAsync(player.UserId.."-stageNumber", player.leaderstats.Stage.Value)
    end)
    if success then
        print("Data Stored Successfully")
    else
        print(errormessage)
    end
end)

Can somebody please help me on how to set a default value? i tried myself and it did not work .

0
i mean you can just make stage.Value = "Your starter value" if that's what you need imKirda 4491 — 3y

Answer this question