【问题标题】:How do I make a Leaderboard on roblox?如何在 roblox 上制作排行榜?
【发布时间】:2011-05-15 10:17:07
【问题描述】:

如何在 roblox 上制作排行榜?

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    需要在每个玩家中插入一个名为“leaderstats”的值,使用带有 PlayerAdded 事件的脚本。在 leaderstats 值中,您可以放置​​ IntValues - 它们的名称将显示为标题,它们的值将显示为玩家的统计数据。

    要更改这些统计信息,您需要向创建 leaderstats 值的脚本添加不同的函数和/或事件。

    【讨论】:

      【解决方案2】:

      在工作区中插入一个脚本,然后在代码中输入:

      function Onplayerentered(player)
      
      local leaderstats = Instance.new("IntValue")
      leaderstats.Parent = player
      leaderstats.Value = 0
      leaderstats.Name = "leaderstats"
      
      local stat = Instance.new("IntValue")
      stat.Name = "" -- Put name here in between the quotations
      stat.Value = -- Put the starting Value#
      
      end
      
      game:GetService("Players").ChildAdded:Connect(Onplayerentered)
      

      【讨论】:

        【解决方案3】:
        1. 调出 roblox 插入工具栏。
        2. 选择排行榜。
        3. 您可以自定义脚本以满足您的需求!

        【讨论】:

        • 也许会提到哪些部分在做什么,以及如何定制。
        【解决方案4】:

        Roblox 排行榜是一个很长的脚本,幸运的是,该脚本允许我们轻松添加和删除 leaderstats。要添加排行榜,请在玩家对象内插入 IntValue,要添加统计信息,请在前导数据中插入 IntValue。

        Roblox 上的大多数游戏都希望每个玩家都拥有相同的排行榜。所以大多数人使用 PlayerAdded 事件并创建排行榜

        【讨论】:

          【解决方案5】:

          在 ServerScriptService 中插入一个脚本并粘贴以下代码:

          plrEntered = function(plr)
              local ls = Instance.new('IntValue') --Leaderstats
              ls.Parent = plr
              ls.Value = 0
              ls.Name = 'leaderstats'
          
              local stat = Instance.new('IntValue')
              stat.Name = 'Money' -- Change to the value you want
              stat.Value = 0 -- Add the starting value
          end
          
          game:GetService'Players'.PlayerAdded(plrEntered)
          

          【讨论】:

            【解决方案6】:

            ROBLOX 将排行榜定义为名为“leaderstats”并位于玩家对象中的对象。排行榜统计定义为 leaderstats 对象(Player>leaderstats>ValueObject)中的一个值对象。因此,让我们编写一个函数,为玩家创建一个包含“现金”统计信息的排行榜。

            local function createLeaderboard(player)
                local stats = Instance.new("Folder")
                stats.Name = "leaderstats"
                local cash = Instance.new("IntValue", stats)
                cash.Name = "Cash"
                stats.Parent = player
            end
            

            然后我们需要完成这项工作。我们需要将此函数连接到来自“Players”对象的“PlayerAdded”事件。

            local players = game:WaitForChild("Players")
            
            players.PlayerAdded:connect(createLeaderboard)
            

            基本上就是这样。 请注意,上面直接显示的代码中的第 3 行相当于:

            players.PlayerAdded:connect(function(player)
                createLeaderboard(player)
            end)
            

            整个脚本如下所示:

            local players = game:WaitForChild("Players")
            
            local function createLeaderboard(player)
                local stats = Instance.new("Folder")
                stats.Name = "leaderstats"
                local cash = Instance.new("IntValue", stats)
                cash.Name = "Cash"
                stats.Parent = player
            end
            
            players.PlayerAdded:connect(createLeaderboard)
            

            建议将脚本放在'ServerScriptService'中。

            【讨论】:

              【解决方案7】:
              function Onplayererntered(player)
              
                  local leaderstats = Instance.new("IntValue")
                  leaderstats.Pareny = player
                  leaderstats.Value = 0
                  leaderstats.Name = "leaderboard"
              
                  local stat = Instance.new("IntValue")
                  statname = "Cash"
                  stat.Value = 100
              
              end
              

              【讨论】:

                【解决方案8】:

                您首先必须在服务器脚本服务中创建一个脚本并将其命名为您想要的任何名称,然后将其写入脚本中(确保其正常脚本不是本地脚本)

                game:GetService("Players").PlayerAdded:Connect(function() --make the function start when new player joins
                    local player = game.Players.PlayerAdded --make player variable
                    local leaderstats = instance.new("Folder", player) --make new folder and set it's parent to the player
                    local money = instance.new("IntValue", leaderstats) --create new value for the stat and set it's parent to the leaderstats folder (you can create as many as u want)
                    money.name = "Money" --make the name of the value
                    money.Value = 0 --make the value's value
                end)
                

                这段代码很简单,有很多 cmet 来解释,希望对你有帮助。

                【讨论】:

                  【解决方案9】:
                  function stats(plr)
                      local leaderstats = Instance.new("IntValue")
                      leaderstats.Name = "leaderstats"
                      leaderstats.Parent = plr
                      
                      local coins = Instance.new("IntValue")
                      Coins.Name = "coins"
                      Coins.Parent = leaderstats
                  end)
                      
                  game.Players.PlayyerAdded:Connect(stats)
                  

                  【讨论】:

                  • 欢迎来到 SO,请将您的代码格式化为代码以使其更易于阅读,在帖子正文中提供您的问题,以及您当前的结果以及您希望的结果。
                  • 我为你格式化了代码。不过,我没有修复您的代码。你定义了coins 但使用Coins 这是错误的。
                  猜你喜欢
                  • 2016-05-27
                  • 2023-03-30
                  • 2021-06-25
                  • 2020-10-28
                  • 2016-10-16
                  • 2022-07-04
                  • 2020-09-10
                  • 2015-10-22
                  • 2020-09-29
                  相关资源
                  最近更新 更多