Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

FindFirstChild returns nil, why?

Asked by
Sam4550 42
7 years ago

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

Log in to vote
2
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

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.

0
Great, thank you! :) Sam4550 42 — 7y
Ad

Answer this question