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

How to fix Humanoid not found while teleporting?

Asked by
Yzuw81 0
3 years ago

When a player joins as the script teleports all players the player that is loading into the game has no character yet and therefore the script cannot find the humanoid of that player... I have no clue how to fix it plz help :) Btw I haven't added a wait for character because idk how to.

2 answers

Log in to vote
0
Answered by 3 years ago

To solve the issue, you need to use the WaitForChild("instance name") method of Instance. What it does is it forces the thread to pause until the Instance with the name passed is found.

In this example it would be something like this:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = workspace:WaitForChild(player.Name)

The reason you do this is that the character is always a child of the workspace and has the name of player.Name. So if your name is Yzuw81, the character is called Yzuw81.

If this solves your issue, please upvote and select this as the answer.

Ad
Log in to vote
0
Answered by 3 years ago

I believe you want to do :WaitForChild("Humanoid") or the :WaitForChild function in general. It works by searching the child of the object you put before it and waiting for a child. Which sounds complicated but it's not really let me give you an example:

local object1 = workspace.Object
local object1Humanoid = object1:WaitForChild("Humanoid")

Answer this question