我如何制作一个 GUI 来显示我收集了多少积木?
How can I make a GUI that shows how many bricks i have collected?
我游戏中的每一块积木都有一个价值,它会被添加到 leaderstats 中。但是,我想要一个 GUI 来显示他们收集了多少 BRICKS。例如,我游戏中的 2 块积木值 32 分,可以存储在 leaderstats 中。我不想显示总数 64,而是显示我收集的砖块数量:2.
这是收集积木并将它们存储在 leaderstats 中的代码:
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)
我想将 leaderstats 保留在右上角,但在屏幕上我还希望它显示收集的砖块数量。有谁知道我如何将其应用到我的游戏中?
制作一个 Main GUI 并在其中插入一个 TextLabel 插入 Int 值和一个脚本并将 MainGUI 放入 The Starter Gui Pack
接下来在脚本中键入以下代码 if 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)
谢谢!
我游戏中的每一块积木都有一个价值,它会被添加到 leaderstats 中。但是,我想要一个 GUI 来显示他们收集了多少 BRICKS。例如,我游戏中的 2 块积木值 32 分,可以存储在 leaderstats 中。我不想显示总数 64,而是显示我收集的砖块数量:2.
这是收集积木并将它们存储在 leaderstats 中的代码:
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)
我想将 leaderstats 保留在右上角,但在屏幕上我还希望它显示收集的砖块数量。有谁知道我如何将其应用到我的游戏中?
制作一个 Main GUI 并在其中插入一个 TextLabel 插入 Int 值和一个脚本并将 MainGUI 放入 The Starter Gui Pack 接下来在脚本中键入以下代码 if 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)
谢谢!