English 中文(简体)
我如何改变全球倡议框架的可见度
原标题:How do I change the visibility of a GUI Frame
  • 时间:2024-01-19 21:43:47
  •  标签:
  • lua
  • roblox

我是新鲜的,我已尝试了几个小时,我无法改变我把我的 game带进我的游戏中。

这是我的法典,我正试图使所谓的“MenuFrame”框架在 but被点击时具有可见度。

https://i.stack.imgur.com/yXSTG.png”rel=“nofollow noreferer”> GUI is under “StarterGUI”

local button = script.Parent
local menu = script.Parent.Parent.Parent:FindFirstAncestor("MenuFrame")

local function onButtonClicked()
    if menu.Visible then
        menu.SetAttribute(menu,Visible,false)
    else
        menu.SetAttribute(menu,Visible,true)
    end
end

button.MouseButton1Down:Connect(onButtonClicked)

The error is 7: attempt to index nil with Visible

是否有关于我可以改变或确定什么的建议。

问题回答

这里有几个问题,首先,你试图通过 tree树,然后叫FindFirstAnce,来找寻。 相反,正如下文所示,你应该直接去做。

Secondly, Visible is a property of GUIs and not an Attribute. Attributes are solely for developer s use and do not change anything regarding the instances themselves see (https://create.roblox.com/docs/studio/properties#instance-attributes) for more info. So instead of calling SetAttribute, just index the Visible property and set it

local button = script.Parent
local menu = script.Parent.Parent.Parent

local function onButtonClicked()
    if menu.Visible then
        menu.Visible = false
    else
        menu.Visible = true
    end
end

button.MouseButton1Down:Connect(onButtonClicked)

此外,为了使你的代码变得更糟,如果发言只是使用某种美术逻辑来歪曲它,那么你可以不这样做。

local function onButtonClicked()
    menu.Visible = not menu.Visible
end




相关问题
Wrapping a Lua object for use in C++ with SWIG

Currently I know how to have C++ objects instantiated and passed around in Lua using SWIG bindings, what I need is the reverse. I am using Lua & C++ & SWIG. I have interfaces in C++ and ...

Can t lua_resume after async_wait?

I have some lua script that have some long running task like getting a web page so I make it yield then the C code handle get page job async, so the thread free to do other job and after a specify ...

How to remove a lua table entry by its key?

I have a lua table that I use as a hashmap, ie with string keys : local map = { foo = 1, bar = 2 } I would like to "pop" an element of this table identified by its key. There is a table.remove() ...

Lua plain string.gsub

I ve hit s small block with string parsing. I have a string like: footage/down/temp/cars_[100]_upper/cars_[100]_upper.exr and I m having difficulty using gsub to delete a portion of the string. ...

why do i get "attempt to call global require (a nil value)"?

I have 3 lua files, Init.lua, FreeCamera.lua and Camera.lua , init.lua calls require "Core.Camera.FreeCamera" Free Camera: module(...) require "Core.Camera.Camera" local M = {} FreeCamera = M M ...

热门标签