我如何在Roblox上制作排行榜?

如何在 Roblox 上制作排行榜?

原文链接 https://stackoverflow.com/questions/4272592

点赞
stackoverflow用户1870451
stackoverflow用户1870451

在每个玩家中需要插入一个名为'leaderstats'的值,使用具有PlayerAdded事件的脚本。在leaderstats值中,您可以放置IntValues-它们的名称是将显示为标题的内容,其值是将显示为玩家统计信息的内容。

要使这些统计数据发生变化,您需要向创建leaderstats值的脚本中添加不同的函数和/或事件。

2010-11-27 21:33:44
stackoverflow用户527173
stackoverflow用户527173

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

function Onplayerentered(player)

local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Value = 0
leaderstats.Name = "leaderstats"

local stat = Instance.new("IntValue")
stat.Name = "" -- 在引号之间填入名称
stat.Value = -- 填写起始值#

end

game:GetService("Players").ChildAdded:Connect(Onplayerentered)
2010-12-01 21:19:47
stackoverflow用户539951
stackoverflow用户539951
  1. 将其添加至roblox插入工具栏。
  2. 选择排行榜。
  3. 您可以根据需要自定义脚本!
2010-12-12 19:01:46
stackoverflow用户3792288
stackoverflow用户3792288

Roblox 排行榜

Roblox 的排行榜脚本非常长,但幸运的是,这个脚本可以让我们轻松地添加和删除 leaderstats。要添加排行榜,只需在玩家对象内添加 IntValue,要添加统计数据,只需在 leaderstats 内添加 IntValue

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

2014-07-01 02:51:39
stackoverflow用户9355667
stackoverflow用户9355667
function Onplayererntered(player)
    -- 当玩家进入游戏时触发的事件

    local leaderstats = Instance.new("IntValue") -- 创建一个 IntValue 类型的对象
    leaderstats.Pareny = player -- 设置它的 Parent 为传入的 player
    leaderstats.Value = 0 -- 初始化数值为 0
    leaderstats.Name = "leaderboard" -- 设置名称为 leaderboard

    local stat = Instance.new("IntValue") -- 创建另一个 IntValue 类型的对象
    statname = "Cash" -- 设置一个名称,但代码中有一个拼写错误
    stat.Value = 100 -- 初始化数值为 100
end
2018-02-13 15:16:51
stackoverflow用户9579570
stackoverflow用户9579570

在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' -- 将其更改为您想要的值
    stat.Value = 0 -- 添加启动值
end

game:GetService'Players'.PlayerAdded(plrEntered)
2018-03-31 18:05:34
stackoverflow用户9808476
stackoverflow用户9808476

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”中。

2018-05-27 17:35:45
stackoverflow用户16591858
stackoverflow用户16591858
## 将下面翻译成中文并且保留原本的 markdown 格式,

```lua
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)

此段代码是一段 Lua 代码,表示在玩家加入游戏时,会调用 stats 函数。stats 函数会创建一个 IntValue 对象并将其命名为 "leaderstats",然后将其作为玩家对象的子物体。接下来,函数会创建另一个 IntValue 对象并将其命名为 "coins",然后将其作为 leaderstats 对象的子物体。

需要注意的是,代码中 Coins 应该改为 coins

2021-08-04 09:56:55
stackoverflow用户18227820
stackoverflow用户18227820

你要先在服务器脚本服务中创建一个脚本,并根据需要将其命名,然后在脚本中编写以下内容(确保它是普通脚本而不是本地脚本):

game:GetService("Players").PlayerAdded:Connect(function() --当有新玩家加入时开始执行该函数
    local player = game.Players.PlayerAdded --创建玩家变量
    local leaderstats = instance.new("Folder", player) --创建新的文件夹并将其父级设置为玩家
    local money = instance.new("IntValue", leaderstats) --创建一个新的值并将其父级设置为 leaderstats 文件夹(可以创建任意数量的值)
    money.name = "Money" --设置值的名称
    money.Value = 0 --设置值的数值
end)

该代码块很简单,有许多注释来解释它,希望它能对你有所帮助。

2022-02-16 22:29:27