I tried to make a script where if I write in a TextBox a name of a player that is in the server he/she will die, but it gives me this error:
attempt to index local 'textBox' (a nil value)
Here's my script:
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)