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

Confusing WaitForChild Problems?

Asked by 9 years ago

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)
0
Also, It worked in studio when I didn't have the WaitForChild(), I just Had .Character SpazzMan502 133 — 9y
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 TheeDeathCaster 2368 — 9y
0
That's what I was thinking, Thanks, I'll read it. SpazzMan502 133 — 9y
0
Thanks! That Wiki Page Really Helped! SpazzMan502 133 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
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)

Ad

Answer this question