Script won't teleport player

  1. What do you want to achieve? Keep it simple and clear!
    I want to teleport a player to a part
  2. What is the issue? Include screenshots / videos if possible!
    Screen Shot 2020-10-21 at 19.03.38
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t thought of anything since it was working before
player.CharacterAdded:connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		local hrp = char:WaitForChild("HumanoidRootPart")
		wait()
		if humanoid and hrp then
			if stage.Value ~= 0 then
				local part = workspace.Checkpoints:FindFirstChild(stage.Value)
				hrp.CFrame = part.CFrame + Vector3.new(0, 1, 0)
			end
		end
	end)
2 Likes

You can use the humanoid:TeleportTo() if needed btw.

1 Like

Not entirely sure, but it might mean that the WaitForChild isn’t working and hrp is returning nil, thus causing the script attempting to find the CFrame of nil. Not entirely sure though. Before you do hrp.CFrame add if hrp ~= nil then

1 Like

first off is it a local script? if so then it will not work. As a local script only effects the player’s client. change the players pos with a normal script if it is a local script. Second: by the looks hrp.CFrame = part.CFrame + Vector3.new(0, 1, 0) you are trying to add on the the CFrame try setting it to a set CFrame hrp.CFrame = part.CFrame

1 Like

It is a server script. I have tried doing that but it still didn’t work.

also you would want to run the code AFTER the player has their stage.Value updated correctly.
So maybe add a number in the wait()

I’d say that something like that could work.

player.CharacterAdded:connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		local hrp = char:WaitForChild("HumanoidRootPart")
                repeat wait() until humanoid ~= nil and hrp ~= nil
		if humanoid ~= nil and hrp ~= nil then
                        repeat wait() until stage.Value ~= 0
			if stage.Value ~= 0 then
				local part = workspace.Checkpoints:FindFirstChild(stage.Value)
                                char:MoveTo(part.Position + Vector3.new(0, 1, 0))
			end
		end
	end)

This still didn’t work. When I tried it, the same error is there.

1 Like

You should edit this to different functions that lets you teleport like character move to or something. If you dont wanna use it and keep use it then tell me. So i can find a solution for you.

No, what I was saying is that in Lua there is a Humanoid:TeleportTo() property.
You need a humanoid varaible though.

Do the following:

print(hrp)
print(part) ← I’m assuming its going to be nil

Tell us what stage.Value is? Is it a stringvalue? ObjectValue, etc>

as the error said, attempt to index nil with cframe, but it only works if it finds the root part. So, your “part” variable, doesn’t exist. We can’t help with that, because we have no idea about this part.