我正在用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)
当商店gui的按钮被按下时,这将打开ShopSelection gui并关闭商店gui。它不起作用。请帮帮我!
发布于 2019-04-15 03:16:26
您的问题是您正在从StarterGui
服务访问对象。一旦播放器加载,StarterGui
会将其内容克隆到播放器的PlayerGui
文件夹中。因此,您需要从那里访问该对象。为此,我们将使用LocalScript
并通过LocalPlayer
对象访问该文件夹。需要注意的是,LocalScripts
只能在播放器直接派生的地方运行,比如StarterPack
、StarterPlayerScripts
、StarterCharacterScripts
或StarterGui
。
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)
希望这能有所帮助!
https://stackoverflow.com/questions/55676724
复制相似问题