Character rotation

i have a queue system and when the player reaches the bend in the queue im trying to make their character face where the tile is facing (look vector) but it won’t work and the player wont move forward if they’re skipped.

the problems in the code:

					fpHRP.CFrame = CFrame.new(fpHRP.Position) * CFrame.Angles(0, math.rad(backTile.Orientation.Y), 0)
					bpHRP.CFrame = CFrame.new(bpHRP.Position) * CFrame.Angles(0, math.rad(frontTile.Orientation.Y), 0)

full code:

function queueModule.SwitchPlayersInTable(p)
	for qpos, plrName in pairs(queueModule.queue) do
		if qpos ~= 1 then
			if plrName == p.Name then
				local BPC = p.Character
				local bpHRP = BPC:WaitForChild("HumanoidRootPart")
				local behindPlayerHum:Humanoid = BPC:WaitForChild("Humanoid")
				local frontPlayer = game.Players:FindFirstChild(queueModule.queue[qpos - 1])
				local FPC = frontPlayer.Character
				local fpHRP = FPC:WaitForChild("HumanoidRootPart")
				local frontPlayerHum:Humanoid = FPC:WaitForChild("Humanoid")
				
				local backTile = queueModule.tilesfolder:FindFirstChild(qpos)
				local frontTile = queueModule.tilesfolder:FindFirstChild(qpos - 1)
				
				
				if frontPlayer then
					print("frontplayer", frontPlayer.Name)
					
					fpHRP.CFrame = CFrame.new(fpHRP.Position) * CFrame.Angles(0, math.rad(backTile.Orientation.Y), 0)
					frontPlayerHum.AutoRotate = false
					frontPlayerHum:MoveTo(backTile.Position)
					frontPlayerHum.MoveToFinished:Connect(function(reached)
						if reached then
							frontPlayerHum.AutoRotate = true
						end
					end)
				end

				if behindPlayerHum then
					bpHRP.CFrame = CFrame.new(bpHRP.Position) * CFrame.Angles(0, math.rad(frontTile.Orientation.Y), 0)
					behindPlayerHum.AutoRotate = false
					behindPlayerHum:MoveTo(frontTile.Position)
					behindPlayerHum.MoveToFinished:Connect(function(reached)
						if reached then
							behindPlayerHum.AutoRotate = true
						end
					end)
				end


				queueModule.queue[qpos], queueModule.queue[qpos - 1] = queueModule.queue[qpos - 1], queueModule.queue[qpos]
				break
			end
		end
	end

	print(queueModule.queue)
end

1 Like
local tilePos = --[[ Position of actual tile]]
local nextTilePos --[[ Position of next tile]]
Root.CFrame = CFrame.new(
Vector3.new(tilePos.X, Root.Position.Y, tilePos.Z),
Vector3.new(nextTilePos.X, Root.Position.Y, nextTilePos.Z))
1 Like

Basically what @xxxwectorxxx said.

fpHRP.CFrame = CFrame.lookAt(fpHRP.Position, Vector3.new(backTile.Position.X, fpHRP.Position.Y, backTile.Position.Z))

Point the root towards the position of the tile but since it’s going to be a different height than the root, only take the X and Z coordinates of the tile and keep the Y coordinate of the root(otherwise your root would for a split second be angled downwards towards the tile which would look weird).

1 Like

hey key, thanks a million for your help! unfortunately it didnt work after i tried your code rip. it prevents the :moveto function from running

hey rin, thanks a million for ur help.
i tried what you said and it rotates the characters in such weird ways haha. i’m still looking on the forum for more resources on this but thank you so much!!