How to teleport a player to a part properly?

Using this script I cant manage to Teleport a player properly to a part. The weird thing it’s that server-side the behavior is correct, but locally not, and that bothers me.

--Put the players on the ready team, put them on the grid too while being anchored
function PutPlayersOnGrid()
	
	local readyPlayers = Teams.Ready:GetPlayers()
	
	local success, errorMessage = pcall(function()
		
		local clonedPlate: Model = ChooseSpawnPlate(#readyPlayers)
		clonedPlate.Parent = workspace.Grid.PlatePositioner
		clonedPlate:MoveTo(clonedPlate.Parent.Position)
		
		local plateSpawnList = {}
		
		for i, part: Part in pairs(clonedPlate:GetChildren()) do
			
			if part.Name == "Spawn" then
				table.insert(plateSpawnList, part)
				
				local tempNEW = Instance.new("Part")
				tempNEW.Parent = workspace
				tempNEW.Position = part.Position
				tempNEW.Anchored = true
			end
		end
		
		--Discard players who died
		for i, player: Player in pairs(readyPlayers) do
			
			if player.Character.Humanoid.Health <= 0 then
				player.Team = Teams.AFK
			end
		end
		
		--Anchor all ready team players on the grid
		--TODO
		for i, player: Player in pairs(readyPlayers) do
			
			local humanRoot: Part = player.Character.HumanoidRootPart
			local humanoid: Humanoid = player.Character.Humanoid
			
			humanRoot.Anchored = true
			humanRoot.CFrame = plateSpawnList[i].CFrame
			
			--player.Character:MoveTo(plateSpawnList[i].Position)
			
			--local rotation = CFrame.Angles(0, math.rad(90), 0)
			--local modelCFrame = player.Character:GetPivot()
			--player.Character:PivotTo(modelCFrame * rotation)
			
			--humanRoot.Position += Vector3.new(0, humanoid.HipHeight, 0)
		
			--player.Character.HumanoidRootPart.CFrame = workspace.Grid.PlatePositioner.CFrame
			
			LookModifierModule.SetSkatesOnLegs(player)

			--Change character position a bit to not overlap with other players
			local variationX = math.random(-22, 22)
			local variationZ = math.random(-22, 22)

			player.Character.HumanoidRootPart.Position += Vector3.new(variationX, 4.25, variationZ)

			--Change character rotation to random
			local variationR = math.random(-180, 180)
			player.Character.HumanoidRootPart.Rotation = Vector3.new(0, variationR, 0)
		end
	end)
	
	if success == true then
		return true
	else
		warn(errorMessage)
		return false
	end
	
end

Here is the behavior serverside:
(Note that the wrong player rotation is not the problem, is expected, but the player appears in the center piece)

Here is the behavior clientside:
The player appears with a different rotation (vertically) and with an offset that I couldnt replicate between play tests. The player should appear on the center.

This bug is a game killer, I would appreciate any help. Thanks :slight_smile:

1 Like

Use an offset (y-axis) to make the player higher on this line, so the HumanoidRootPart is not positioned in the center of the part:

humanRoot.CFrame = plateSpawnList[i].CFrame * CFrame.new(0, 10, 0)

and make sure the part is pointing up :point_up_2:
image

Also there’s no “Rotation” property on the HumanoidRootPart

image

1 Like

If HumanoidRootPart is anchored, the position of the HumanoidRootPart on the client will not replicate to the server.

1 Like

Ok, self solved the problem. It was the most silly thing that could be…

Forgot to delete these lines

--Change character position a bit to not overlap with other players
local variationX = math.random(-22, 22)
local variationZ = math.random(-22, 22)

player.Character.HumanoidRootPart.Position += Vector3.new(variationX, 4.25, variationZ)

--Change character rotation to random
local variationR = math.random(-180, 180)
player.Character.HumanoidRootPart.Rotation = Vector3.new(0, variationR, 0)

Anyways thanks for the help, and I didnt know the replication thing.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.