When player respawns it doesn't go where I ask it to!

for _,v in pairs(Players:GetPlayers()) do 
	local Char = v.Character or v.CharacterAdded:Wait()
	local HMR = Char:WaitForChild("HumanoidRootPart")
	HMR.Anchored = true
	Char:SetPrimaryPartCFrame(CFrame.new(MapDictionary[clone.Name]["spawnLoc"])) -- This part works as intended
	HMR.Anchored = false


	v.CharacterAdded:Connect(function(Char)
		local HMR = Char:WaitForChild("HumanoidRootPart")
		HMR.Anchored = true
		Char:SetPrimaryPartCFrame(CFrame.new(MapDictionary[clone.Name]["spawnLoc"])) -- This part doesn't the player just drops from 0, 0, 0
		HMR.Anchored = false
	end)
end

So bassicaly when the player dies and respawns instead of going to where I ask it to, It drops from the sky at vector(0, 0, 0)

Don’t use CFrame.new() for these stuffs. Use Part.CFrame instead.

1 Like

I’m not sure how I can use the if I’m using SetPrimaryPartCFrame but I can try a diffrent method

I have made some small changes

	for _,v in pairs(Players:GetPlayers()) do 
		local Char = v.Character or v.CharacterAdded:Wait()
		local HMR = Char:WaitForChild("HumanoidRootPart")
		HMR.Anchored = true
		Char:SetPrimaryPartCFrame(CFrame.new(MapDictionary[clone.Name]["spawnLoc"]))
		HMR.Anchored = false
		
		
		v.CharacterAdded:Connect(function(Char2)
			
			local HMR = Char2:WaitForChild("HumanoidRootPart")
			HMR.Anchored = true
			Char2.PrimaryPart = HMR
			Char2:SetPrimaryPartCFrame(CFrame.new(MapDictionary[clone.Name]["spawnLoc"]))
			
			HMR.Anchored = false
		end)
	end

and my MapDictionary[clone.Name]["spawnLoc] is a vector3 value so I’m not sure how to do HMR.CFrame

HMR.CFrame = ??

Do you get any errors? If so, it may solve/explain the problem for you.

Nvm I missunderstood. Just get the checkpoint part and get its CFrame. Something like this:
Char2:SetPrimaryPartCFrame(checkpoint.CFrame)
Also, you don’t need to set the char’s PrimaryPart to HumanoidRootPart as it always is.

1 Like

I have no errors the first half of the code im satisfied with but the the code under the characterAdded event im not

Can you explain more

so should I get the humanoidRootPart and change its cframe?

I tried doing this but I get the same result

HMR.CFrame = CFrame.new(MapDictionary[clone.Name]["spawnLoc"])
``

I don’t know if MapDictionary[clone.Name]["spawnLoc"] is a Vector3 or Part. But, again

its a vector3 value
image

why shouldn’t I use CFrame.new()

Also I have tried using this but it doesn’t work

HMR.CFrame = CFrame.new(MapDictionary[clone.Name]["spawnLoc"])
Char:SetPrimaryPartCFrame(MapDictionary[clone.Name]["spawnLoc"].CFrame) -- This part works as intended

I tried that it doesn’t work

Do this.

Char2.HumanoidRootPart.CFrame =

I tried that to before, I guess I will have to find a different way

I found a work around instead of teleporting the players though the characterAdded event, what I did was create a spawn part for each map