WaitForChild return nil Everytime

  1. What do you want to achieve? i want to move the Player model to a different Folder in the workspace.

  2. What is the issue? everytime i run the code i use WaitForChild() but it return nil everytime.

  3. What solutions have you tried so far? i have looked on the developer hub and found nothing, i tried changing the variable’s names but to no avail.

		local player = selectPlayer()
		print(player.Name)
		local Hdescription = Players:GetHumanoidDescriptionFromUserId(player.UserId)
		local playchar = game.Workspace.Game:WaitForChild(player.Name,5)
		print(#game.Workspace.Game:GetChildren())
		print(playchar)
		playchar.Parent = workspace.Lobby --error occurs here

This means that your code wasn’t able to find an instance named player.Name before the 5 seconds you have specified passed. Try removing the second argument and it should give you an infinite yield warning. That is just a warning meaning that it takes more than 5 seconds to find the instance, it won’t break the script. However if the script never continues(so you never see the prints in the console) then it’s an actual infinite yield, which explains the behaviour you’re encountering.

1 Like

yeah i’ve tried that but it never finds it, but when i look in the hierarchy i can see the object in the correct folder but the script wont find it.

1 Like

Why do you need to use game.Workspace.Game:WaitForChild(player.Name,5) to find the character? Can you use player.Character or player.CharacterAdded:Wait() instead?

3 Likes

The problem is that player.Name is a string, henceforth the player’s name does not have a parent. As what J_Angry said above, it would be more efficient to use player.Character then the method you are trying currently because player.Character would be an object within your game.

1 Like

ok that solves the first problem, but now i have a new problem, i cant seem to move the player character to another folder using “.Parent”

1 Like

Try using workspace:WaitForChild("Lobby") to ensure it exists and can be found.

this didnt work, the player model still stays in the first “Game” folder instead of moving to the “Lobby” folder

1 Like

Maybe you aren’t supposed to. I haven’t seen any games changing the default character location(workspace), unless they implement some kind of custom character system.

1 Like

@NyrionDev, you can move the player’s parent to a different location, because I tried it with a script in ServerScriptService and a folder in workspace, and it worked.

For OP, can you send a screenshot of your workspace? You’re code seems fine, so there could be a problem there.

1 Like

Make sure the character model has Archivable set to true in order to change the character’s parent. Simply implementing code like:

playchar.Archivable = True

should fix the issue.

Edit - This was my reference: How to change player character parent - #10 by pienter2

1 Like

I figured it out!, i just made a for loop in which i go throught every player and move them like that and the selected player wont be moved!

Thanks for all of your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.