接近提示一个可见的图像标签更改不起作用



我正在努力使其在使用接近提示时,图像标签变得可见,但它不起作用,我该如何解决这个问题?

local proximity = workspace.Cardpack.ProximityPrompt
local proximityPromptService = game.GetService("ProximityPromptService")
proximity.Triggered:Connect(function()
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible
end)

您实际上不需要使用_G。相反,我们可以直接向X1声明它。

local prompt = workspace.Cardpack.ProximityPrompt
local x1 = workspace.Inventory.Frame.X1
prompt.Triggered:Connect(function()
x1.Visible = not x1.Visible
end)
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible

这就是你的剧本完全错误的地方。这不是LUA语法,也不是编程的工作方式。这实际上是你目前正在尝试做的事情。

local value = true = false;

实际上,您应该做的是创建对您试图设置的ImageLabel的引用。然后更改它的属性。在全局环境中设置变量不会更改ImageLabel的属性。

local ProximityPromptService = game.GetService("ProximityPromptService");
local ImageLabel = workspace.Inventory.Frame.X1;
local Proximity = workspace.Cardpack.ProximityPrompt;

proximity.Triggered:Connect(function()
ImageLabel.Visible = true;
end)

这似乎是一个简单的问题,可以用简单的解决方案来解决(前提是你知道自己在做什么(。现在需要注意的是:

  • 您不需要使用;'你几乎在人们写的每一行字上都能看到。这不是强制性的,也不应该是强制性的。尽管这对你想要少行的时候很好(如果你喜欢的话(
  • 你不想在同一行上有2=,因为这不是正确的语法(正如@sl0th所说(,你不能尝试这样的任务,因为它甚至不起作用。无论如何,你希望它不只是把它改回假的
  • 当你编写这个代码时,我不相信你完全理解它是如何工作的,要制作代码,你首先必须完全或相当流利地理解它的工作原理。所以让我们从这个开始吧

我们如何做到这一点?让我们看看:

-- Perhaps put the script INSIDE of the Cardpack, and then do it from here.
-- Also, I'm not sure why you've put an "inventory.Frame" here, if it's a screengui then it should go in StarterGui, however if it's a billboardgui then please ignore me.
local Cardpack = script.Parent -- I've added it inside the cardpack as said.
local Prompt = Cardpack.ProximityPrompt
local Label = workspace.Inventory.Frame.X1 -- using the original directory as I don't know how your explorer looks.
local CanBeVisible = false -- if you want to toggle it.
Prompt.Triggered:Connect(function() -- make sure to look up on devforum about this.
if not CanbeVisible then -- "not CanBeVisible" is equivalent to "CanBeVisible==false".
CanBeVisible = true
Label.Visible = true
else -- if it's true and not false:
CanBeVisible = false
Label.Visible = false
end
end)

这是一个更"可接受";编码方式。人们有自己的喜好,但通常我会根据你的喜好来做。如果你不太了解,我会一直在这里帮助你!:D

最后注释:

local A,B = "A", "B" -- you can assign multiple variables on a single line!
A,B = "B", "A" -- and you can also change more than one on the same line too.
local A = "A";print(A) -- that's how ; is used if you want to do more than one thing on the same line (but not done at the the same time on the same line!). ; Seperates the code without needing to add spaces, though adding/casting variables you should stick to using the comma(s) to separate them assigning new values and whatnot.

此外,您甚至不需要ProximityPromptService变量,因为您从未使用过它!你不能只做game.GetService(..),你最好做game:GetService(..)

我希望这对你有帮助,如果真的有帮助,请将其标记为答案!虽然这是我第一次尝试帮助别人,但我尽力了。哈哈。

最新更新