【问题标题】:How do you open and close a gui in Roblox?如何在 Roblox 中打开和关闭 gui?
【发布时间】:2019-09-04 16:48:20
【问题描述】:

我在 Roblox 中制作游戏时遇到了一个错误。我正在尝试制作在游戏中打开商店的 gui 按钮。但是打不开。

我试图让按钮不可见而商店可见。一切都很好,但 guis 不会变得可见/不可见。它说更改了 gui 在属性中的可见性,但它没有在游戏中显示。我还尝试更改 gui 的父级,它可以关闭但不能打开。

gui = game.StarterGui.ShopSelection
button = game.StarterGui.Shop.Button
button.MouseButton1Down:Connect(function()
    gui.Visible = true
    button.Parent.Visible = false
end)

这应该在按下 Shop gui 的按钮时打开 ShopSelection gui 并关闭 Shop gui。它不工作。请帮忙!

【问题讨论】:

    标签: roblox


    【解决方案1】:

    您的问题是您正在从StarterGui 服务访问对象。一旦播放器加载,StarterGui 会将其内容克隆到播放器的 PlayerGui 文件夹中。因此,您需要从那里访问对象。为此,我们将使用LocalScript 并通过LocalPlayer 对象访问该文件夹。请注意,LocalScripts 只能在玩家的直系后代中运行,例如 StarterPackStarterPlayerScriptsStarterCharacterScriptsStarterGui

    local Players = game:GetService("Players")
    local player = Players.LocalPlayer
    local gui = player:WaitForChild("PlayerGui"):WaitForChild("ShopSelection") --wait for objects
    local button = player.PlayerGui:WaitForChild("Shop") --:WaitForChild() yields the thread until the given object is found, so we don't have to wait anymore.
    
    button.MouseButton1Down:Connect(function()
        gui.Visible = true
        button.Visible = false
    end)
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2016-05-26
      • 2020-12-20
      • 2022-11-08
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多