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

Confusing WaitForChild Problems?

So I have a working Teleport GUI, Or at least It works in studio.

It makes a ParticleEmitter Appear in the Character's Torso, then teleport them to a shop area.

When I tried it out in Play Mode, it Didn't working saying that the character was nil

The obvious Solution was to put :WaitForChild("Character") And let it do it after the character loads.

But the problem is, the character loads all of its clothes and hats and faces and everything, but it still doesn't let me teleport.

I think the problem is I have the wrong way to get the character from player, but I don't know...

Here's the Localscript that teleports you on click:

character = game.Players.LocalPlayer:WaitForChild("Character")

Sparkles = Instance.new("ParticleEmitter")
script.Parent.MouseButton1Down:connect(function(bloop)
	Sparkles.Rate = 50
	Sparkles.Parent = character.Torso
	wait(3)
	character.Torso.CFrame = CFrame.new(Vector3.new(-6195.655, -244.6, -103.183))
	Sparkles.Enabled = false
end)

4 comments

0

Also, It worked in studio when I didn't have the WaitForChild(), I just Had .Character

2

You can not get the Player's Character from the 'WaitForChild' method, because it is yielding the code until an Instance within the name 'Character' is existant within the Player, not the actual Character itself! Also, there is a Documentary about this on the WIKI: http://wiki.roblox.com/index.php?title=Character

0

That's what I was thinking, Thanks, I'll read it.

0

Thanks! That Wiki Page Really Helped!

1 answer

character = game.Players.LocalPlayer:WaitForChild("Character")

That's waiting for a child of the player called Character, not the actual character. That's why. You want to either use player.CharacterAdded which returns the character, or do something like game.Workspace:WaitForChild(game.Playres.LocalPlayer.Name)

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