首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Roblox中打开和关闭gui?

如何在Roblox中打开和关闭gui?
EN

Stack Overflow用户
提问于 2019-04-14 23:06:45
回答 1查看 597关注 0票数 0

我正在用Roblox做游戏,我遇到了一个错误。我正在尝试制作游戏中打开店铺的gui按钮。但它打不开。

我试着使按钮不可见,但商店可见。一切都很好,但guis不会变得可见/不可见。它说在属性中gui的可见性的变化,但它没有在游戏中显示出来。我还试着更改了gui的父界面,它可以关闭,但不能打开。

代码语言:javascript
运行
复制
gui = game.StarterGui.ShopSelection
button = game.StarterGui.Shop.Button
button.MouseButton1Down:Connect(function()
    gui.Visible = true
    button.Parent.Visible = false
end)

当商店gui的按钮被按下时,这将打开ShopSelection gui并关闭商店gui。它不起作用。请帮帮我!

EN

Stack Overflow用户

回答已采纳

发布于 2019-04-15 03:16:26

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

代码语言:javascript
运行
复制
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)

希望这能有所帮助!

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55676724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档