我試圖製作一個腳本,如果我在文本框中寫入名爲 的玩家在服務器中,他/她會死,但它給了我這個錯誤:嘗試索引文本框導致無值
attempt to index local 'textBox' (a nil value)
這裏是我的腳本:
local screenGui = script.Parent
local textBox = screenGui:FindFirstChild("TextBox", true)
textBox.FocusLost:Connect(function(enterPressed)
--[[This function is called every time the TextBox is "unfocused". A TextBox is "focused" when the player is typing in it, and "unfocused" when they're doing something else.]]
--[[a parameter is passed to this function, "enterPressed". This is true if the player unfocused the TextBox by pressing enter. Another way to unfocus it is by clicking somewhere outside it.]]
--Try to find a player with the name of whatever is in the TextBox
local player = game.Players:FindFirstChild(textBox.Text)
if player then --Check if we found that player
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid") --try to find the humanoid
if humanoid then --check if we found that humanoid
humanoid.Health = 0 --kill the humanoid
end
end
end)
也許,而不是textBox使用TextBox? –