【发布时间】:2018-01-12 07:02:41
【问题描述】:
我试图制作一个脚本,如果我在 TextBox 中写一个名字 服务器中的玩家他/她会死,但它给了我这个错误:
尝试索引本地'textBox'(一个零值)
这是我的脚本:
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?