我正在嘗試這樣做,以便當您使用接近提示時,影像標簽變得可見但它不起作用,我該如何解決這個問題?
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)
uj5u.com熱心網友回復:
你真的不需要為此使用 _G 。相反,我們可以直接將其宣告給X1.
local prompt = workspace.Cardpack.ProximityPrompt
local x1 = workspace.Inventory.Frame.X1
prompt.Triggered:Connect(function()
x1.Visible = not x1.Visible
end)
uj5u.com熱心網友回復:
_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)
uj5u.com熱心網友回復:
這似乎是一個簡單的問題,可以通過簡單的解決方案來解決(假設您知道自己在做什么)。現在這里有一些注意事項:
- 您不需要使用 ; ,您幾乎可以在人們制作的每一行中看到。這不是強制性的,也不應該是。雖然它適用于您想要更少的線條(如果這是您的偏好)。
- 您不希望在同一行上有 2 個 =,因為它不是正確的語法(正如 @sl0th 所說),您不能嘗試這樣的任務,因為它甚至不起作用。您希望它不只是將其更改回 false 反正。
- 當您撰寫此代碼時,我不相信您完全理解它是如何作業的,并且要撰寫代碼,您首先必須完全或者相當流利地理解它是如何作業的。所以讓我們從那個開始吧!
我們如何做到這一點?讓我們來看看:
-- 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(..)。
我希望這對您有所幫助,如果確實如此,請將其標記為答案!雖然這是我第一次嘗試幫助別人,但我盡力了哈哈。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/443139.html
