如何制作一个显示我已经收集了多少个砖块的GUI?

我的游戏中的每个砖块都有一个价值,并且它们会被添加到排行榜中。但是,我想要一个GUI来显示他们已经收集了多少个砖块。例如,我的游戏中的2个砖块价值为32分,将被存储在排行榜中。我不想显示总数64,我想显示我收集的砖块数量:2。

下面是收集砖块并将其存储在排行榜中的代码:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.ElectoralVotes.Value = player.leaderstats.ElectoralVotes.Value + 37.5
            script.Sound:Play()
            wait(1)
            script.Parent:Remove()
        end
    end
end)

我想在右上角保留排行榜,但是我也想在屏幕上显示收集的砖块数量。有没有人知道我怎样将其实现到我的游戏里?

点赞
用户14312523
用户14312523

创建一个主 GUI,并在其中插入一个 TextLabel,插入 Int 值和一个脚本,并将 MainGUI 放入 Starter Gui Pack 中。接下来,在 TextLabel 的脚本中输入以下代码:

local my_text_gui = script.Parent.TextLabel
local brick_count = my_gui.IntValue
local function change_value()
     my_text_gui.Text = brick_count.Value

brick_count:GetPropertyChangedSignal("Value"):Connect(change_value())

然后更改触碰检测脚本,并添加下面给出的值添加代码(仅在触碰检测脚本不是本地脚本时起作用):

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.ElectoralVotes.Value = player.leaderstats.ElectoralVotes.Value + 37.5
            hit.Parent.PlayerGui.Your_Brick_Counter_GUI.IntValue = hit.Parent.PlayerGui.Your_Brick_Counter_GUI.IntValue + 1
            script.Sound:Play()
            wait(1)
            script.Parent:Remove()
        end
    end
end)
2020-11-25 12:41:15