ROBLOX STUDIO HOW TO ADD LEADERBOARD WITH SAVING DATA IN ROBLOX STUDIO!

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024
  • ROBLOX STUDIO HOW TO ADD LEADERBOARD WITH SAVING DATA IN ROBLOX STUDIO!
    in this video you will learn how to save leaderstas to storage.
    Scripts :
    ----------------------------------------------------------
    local DataStoreService = game:GetService("DataStoreService")
    local playerDataStore = DataStoreService:GetDataStore("storage")
    game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0
    coins.Parent = leaderstats
    -- Load data
    local success, data = pcall(function()
    return playerDataStore:GetAsync(player.UserId)
    end)
    if success and data then
    coins.Value = data.coins or coins.Value
    end
    end)
    game.Players.PlayerRemoving:Connect(function(player)
    -- Save data
    local success, error = pcall(function()
    playerDataStore:SetAsync(player.UserId, {
    coins = player.leaderstats.Coins.Value,
    })
    end)
    if not success then
    warn("Failed to save data for player " .. player.Name .. ": " .. error)
    end
    end)
    -- Increase coins every second
    while true do
    wait(1)
    for _, player in ipairs(game.Players:GetPlayers()) do
    if player and player:FindFirstChild("leaderstats") then
    local coins = player.leaderstats.Coins
    if coins then
    coins.Value = coins.Value + 1
    end
    end
    end
    end
    ----------------------------------------------------------
    🌟 Our Roblox Game: www.roblox.com...
    🚀 (Check out my UGC Items): www.roblox.com...
    🔥 (Explore my Talent Hub): create.roblox....
    Connect with me:
    🐦 Twitter: / cebrailblox
    🎮 Roblox: www.roblox.com...
    Good Roblox Groups :
    UGC-Factory : www.roblox.com...
    eyh.dev : www.roblox.com...
    SOZANZAINAL : www.roblox.com...
    👍 Don't forget to Like & Subscribe for more Roblox tutorials and game development insights!
    🔗 Keywords: #roblox #robloxstudio #robloxgames #robloxedit

ความคิดเห็น • 6

  • @carltyrhon123vidal4
    @carltyrhon123vidal4 4 หลายเดือนก่อน

    Fam your the goat

  • @carterchmilar
    @carterchmilar 7 หลายเดือนก่อน +1

    I love your videos! :D

    • @BlackHoleLabs
      @BlackHoleLabs  7 หลายเดือนก่อน

      Thank you so much! can you send me your roblox and discord name? i wanna make you friend at both platforms.

  • @GamingHub014
    @GamingHub014 7 หลายเดือนก่อน +2

    I tried to use this with the hide and seek tutorial and it doesn't work

  • @carltyrhon123vidal4
    @carltyrhon123vidal4 4 หลายเดือนก่อน

    can u do like a gun for the code

  • @88cd88cd
    @88cd88cd 5 หลายเดือนก่อน

    it aint saves