Trying to set player cframe

I am trying to set the players CFrame to a parts cframe in a folder every time they respawn;

player.CharacterAdded:Connect(function(char)
		
		if player.leaderstats.Stage.Value ~= 0 then
			local spawnPart = workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Name)
			char.HumanoidRootPart.CFrame = spawnPart.CFrame + Vector3.new(0,1,0)
		end

But I get this error:
image

Why?

1 Like

maybe because spawnPart is nil. You should probably try and print spawnPart

char:WaitForChild("HumanoidRootPart").CFrame = spawnPart.CFrame * CFrame.new(0,1,0)
1 Like

yea that is true it could be the humanoid root part that is nil

Yea so I made an error but I fixed but it still wont bring me to the part:

	player.CharacterAdded:Connect(function(char)
		
		if player.leaderstats.Stage.Value ~= 0 then
			local spawnPart = workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Value)
			char.HumanoidRootPart.CFrame = spawnPart.CFrame + Vector3.new(0,1,0)
		end

I believe the issue is the way you are getting the spawnPart. You are reading the name of the leaderstats Stage object which returns Stage, however, you probably want to use Value.

Try replacing

local spawnPart = workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Name)

with

local spawnPart = workspace.Checkpoints:FindFirstChild(player.leaderstats.Stage.Value)

I did there is no error but it just wont teleport me to the part

Can you show the full script? You may have an issue with a different part of the script.

THe prints work Ia dded them:


image