How to change player`s rotation to part rotation in a while loop without stopping player

Hello, i have one question. i have a script in a while loop:

player.Character:PivotTo(CFrame.new(player.Character.HumanoidRootPart.Position) * playersPlace.CFrame.Rotation)

So, in the loop, when i do humanoid:MoveTo(pos) the player WONT move because the function above.

MAIN QUESTION How can i stop it from stopping the player or is there anothey way to rotate player to parts orientation?

Let me know! Thank you!

May you put the entire script?

1 Like

oh, its in module script, here is the function that is character rotating is stored in

`main.WhileLoop = function(player) 
	while task.wait(0.05) do
main.NextPosition(player)
		local playersPlace	: Part --finding the current place part the player is in rn

		for i, placePart in Places:GetChildren() do
			if placePart.Place.Value == player.Other.CurrentPlace.Value then
				playersPlace = placePart
			end
		end
		player.Character:PivotTo(CFrame.new(player.Character.HumanoidRootPart.Position) * playersPlace.CFrame.Rotation)
		end
end`

and here is player moving function

local place
	local price = MoneyByPlace.SecondPlaceCost / (MoneyByPlace.DecreaseCost * player.Other.CurrentPlace.Value)
	
	if gamepassVal then
		
		for i, placePart in Places:GetChildren() do
			if placePart.Place.Value == player.Other.CurrentPlace.Value - 1 then
					place = placePart
			end
		end
	else
		
	for i, placePart in Places:GetChildren() do
		if placePart.Place.Value == player.Other.CurrentPlace.Value - 1 then
			if player.Other.Money.Value >= price then
			place = placePart
			end
		end
	end
	
	end
	
	if place then
		player.Other.CurrentPlace.Value -= 1
		task.spawn(function()
			local prevOccupant = workspace:FindFirstChild(place.Occupant.Value)
		player.Character.Humanoid:MoveTo(place.Position)
		player.Other.Money.Value -= price
		place.Occupant.Value = player.Name
		if prevOccupant then
			prevOccupant.Humanoid:MoveTo(playersPlace.Position)
		playersPlace.Occupant.Value = prevOccupant.Name --this will be another player in the future!!
		end
		end)

If you only need to change the player’s orientation I recommend using AlignOrientation.

AlignOrientation.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * playersPlace.CFrame.Rotation;

Set the Mode property to OneAttachment and set the attachment to the one you find in the HumanoidRootPart of the player’s character

1 Like

Thank you so much! That indeed works well!

1 Like

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