【发布时间】:2021-08-25 01:09:40
【问题描述】:
用于 roblox lua 游戏。
我正在尝试制作一个可绑定函数,在玩家点击文本框后,输入一些内容,然后点击输入/返回,它将单词存储在服务器中,然后将其打印到输出中。现在打字方面的一切都可以工作了,它甚至可以在surfacegui上打印出来。问题是,如果我尝试运行代码,我会收到错误“尝试调用零值”。这是我在框中输入的调用代码。
local screenTextBox = script.Parent -- Location of Textbox on the screen
local partTextLabel = game.Workspace.BlueTeamGameRoom.BlueGameBoard.Board.SurfaceGui.TextBox -- Location of text on block
while true do --code to update the screengui
wait(.5)--wait in order to keep roblox studio from crapping itself
screenTextBox.FocusLost:connect()--for clicking on the textbox
partTextLabel.Text = screenTextBox.Text -- Change text
end
screenTextBox.FocusLost:connect(function(enterPressed) --defining enterpressed(clicking enter) within the parameters of the player clicking the box
if enterPressed then
local DBallz = game.ReplicatedStorage.answerVerify:Invoke() --calling the bindable function
print(DBallz)--printing what the bindable function returns
end
end)
这是我的 OnInvoke 代码,用于打印框中的单词
game.ReplicatedStorage.answerVerify.OnInvoke = function()
local Text = game.StarterGui.ScreenGui.wordSend.TextBox.Text --defining the property of the text of the textbox
return Text --sending the text to the local script
end
我尝试过使用 InvokeServer 和 OnServerInvoke,但没有区别。在那里,我还尝试使用不同的方式来编写键码映射,但这也不起作用。并且调用代码位于 localScript 中,它是用户必须输入的文本框的子项。调用代码位于作为工作区子项的常规服务器端脚本中。
【问题讨论】:
-
类似的错误带有堆栈跟踪、行号和名称。那么您要调用哪个 nil 值?请阅读How to Ask
-
@Piglet 好吧,首先,奇怪的是,错误并没有伴随堆栈跟踪、行号或名称出现,但现在看它似乎不是 nil 值是我的问题,因为如果我在文本框中的任何地方按 enter,它会说尝试调用 nil 值。即使不使用 enterPressed