I have a teleportation localscript that teleports the player to a part of the map when a GUI is clicked..
It works perfectly in studio, but in play mode it doesn't work, saying that it's attempting to index a nil value (character)
I don't really know what the problem is, because I can't WaitForChild() the character.
The localscript inside of a gui
player = game.Players.LocalPlayer
character = player.Character
human = character:WaitForChild("Humanoid")
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
character = game.Players.LocalPlayer.Character
Sparkles = Instance.new("ParticleEmitter")
script.Parent.MouseButton1Down:connect(function(bloop)
Sparkles.Rate = 50
Sparkles.Parent = character.Torso
wait(2)
character.Torso.CFrame = CFrame.new(Vector3.new(-14, 9.5, 28.4))
Sparkles.Enabled = false
human.WalkSpeed = 25
script.Parent.Visible = false
script.Parent.Parent.Spawn.Visible = true
end)

6 comments
In a lot (or some cases), the 'Character' property will be 'nil' before the actual Character for the Player has become existant, until then, it will return 'nil' until the Character is existant, then set the Player's Character property to the Character. :P (I didn't notice this until I did some testing with my own codes ;-;).
So how can I fix this?
Looking at the code, you are calling the 'WaitForChild' method on line 3 'WaitForChild("Humanoid")' on the Player's Character when the Player's Character could be Non-Existant (or nil) at that current time. :P
repeat wait() until character end
Thank you Alpha! I moved the WaitFoChild Down the script, and it works now!
No problem, glad to help man! :D