Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

FindFirstChild returns nil, why?

Here, plr always returns a nil value. What am I doing wrong and how should it look instead?

username = script.Parent.Parent.TextBox.Text
plr = game.Players:FindFirstChild(username)

while true do
	print(plr.Name)
	wait(10)
end

1 answer

✓ Accepted answer

Lines 1 and 2 run once. The initial values don't change, because you don't tell them to. You can remedy this easily:

while true do
    local username = script.Parent.Parent.TextBox.Text --// Use local variables
    local plr = game.Players:FindFirstChild(username)
    print(plr.Name)
    wait(10)
end

However, you'd probably be able to do whatever you plan to do here using the Changed event. I'd recommend reading up on it.

Hope this helped.

1 comment

0

Great, thank you! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.