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

FindFirstChild() not working when I put in a StringValue.Value?

Asked by 5 years ago

When I use FindFirstChild() and input a StringValue.Value into the "()" it returns nil even tho I the value says there is something in the value. The error says that the FindFirstChild() can not index a nil value even tho I checked the player's gui while the game is running and have a print statement and the print statement says there is something in the value and then for some reason the FindFirstChild() with the value does not work and returns nil. pls help

print(SelectedValue.Value)
player.PlayersArmor:FindFirstChild(SelectedValue.Value).Parent = player.Character.Armor

2 answers

Log in to vote
0
Answered by 5 years ago

if the print line works


print(SelectedValue.Value)

and you checked the value it prints is identical to the name you see while the game is running, the only possibility of this error is when this line is called

player.PlayersArmor:FindFirstChild(SelectedValue.Value).Parent = player.Character.Armor 

your PlayersArmor has not been loaded yet, put in wait(10) or wait(50) to make sure it works, then reduce the timer.

0
Please don't do that ^ Psudar 882 — 5y
Ad
Log in to vote
0
Answered by
Psudar 882 Moderation Voter
5 years ago
Edited 5 years ago

You need to do something like this:

player.PlayersArmor:FindFirstChild("SelectedValue").Parent = player.Character.Armor

This is because you can't use WaitForChild on a property, which is what you were doing with SelectedValue.Value.

Should be a simple fix, hope this helped.

Answer this question