How can I make the rig rotate when it reaches to the StopPart?

So basically I want the Rig to rotate to its right when It has stopped moving and reached to StopPart but I have tried everything and nothing has worked so far.

local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local retroFolder = Workspace:WaitForChild("RetroSlops")
local notRetroFolder = Workspace:WaitForChild("NotRetroSlops")
local spawnPart = Workspace:WaitForChild("SpawnPart")
local stopPart = Workspace:WaitForChild("StopPart")

local function addAnimate(rig)
	local humanoid = rig:FindFirstChild("Humanoid")
	if not humanoid then return end

	local animator = humanoid:FindFirstChildOfClass("Animator")
	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local idleAnim = Instance.new("Animation")
	idleAnim.AnimationId = "http://www.roblox.com/asset/?id=180435571"
	local idleTrack = animator:LoadAnimation(idleAnim)

	local walkAnim = Instance.new("Animation")
	walkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
	local walkTrack = animator:LoadAnimation(walkAnim)

	idleTrack:Play()

	humanoid.Running:Connect(function(speed)
		if speed > 0 then
			if not walkTrack.IsPlaying then
				idleTrack:Stop()
				walkTrack:Play()
			end
		else
			if not idleTrack.IsPlaying then
				walkTrack:Stop()
				idleTrack:Play()
			end
		end
	end)
end

local function spawnRig()
	local chosenFolder = math.random(1,2) == 1 and retroFolder or notRetroFolder
	local rig = chosenFolder:GetChildren()[1]
	if not rig then
		warn("No rig found in chosen folder")
		return
	end

	local newRig = rig:Clone()
	newRig.Parent = Workspace

	local hrp = newRig:WaitForChild("HumanoidRootPart") :: Part
	local humanoid = newRig:WaitForChild("Humanoid") :: Humanoid

	hrp.Anchored = false
	humanoid.WalkSpeed = 4
	humanoid.AutoRotate = true

	addAnimate(newRig)

	hrp.CFrame = CFrame.new(spawnPart.Position + Vector3.new(0, hrp.Size.Y/2, 0))

	local stopCenter = stopPart.Position + Vector3.new(0, 0, 1)
	humanoid:MoveTo(stopCenter)
	local conn
	conn = RunService.Heartbeat:Connect(function()
		local distance = (hrp.Position - stopCenter).Magnitude

		if distance < 0.5 then
			conn:Disconnect()

			humanoid:Move(Vector3.new(0,0,0), false)
			humanoid.PlatformStand = true
			humanoid.AutoRotate = false

			hrp.Anchored = true
			hrp.CFrame = CFrame.new(stopCenter)

			local currentLook = hrp.CFrame.LookVector
			local rightLook = Vector3.new(currentLook.Z, 0, -currentLook.X)
			hrp.CFrame = CFrame.new(stopCenter, stopCenter + rightLook)

			for _, part in ipairs(newRig:GetDescendants()) do
				if part:IsA("BasePart") and part ~= hrp then
					local weld = Instance.new("WeldConstraint")
					weld.Part0 = hrp
					weld.Part1 = part
					weld.Parent = part
				end
			end
		end
	end)
end

spawnRig()

Instead of messing with LookVector, just use CFrame.Angles to rotate 90° on Y when it stops.

1 Like

Didn’t work sadly…

local Workspace = game:GetService(“Workspace”)
local RunService = game:GetService(“RunService”)

local retroFolder = Workspace:WaitForChild(“RetroSlops”)
local notRetroFolder = Workspace:WaitForChild(“NotRetroSlops”)
local spawnPart = Workspace:WaitForChild(“SpawnPart”)
local stopPart = Workspace:WaitForChild(“StopPart”)

local function addAnimate(rig)
local humanoid = rig:FindFirstChild(“Humanoid”)
if not humanoid then return end

local animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
	animator = Instance.new("Animator")
	animator.Parent = humanoid
end

local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "http://www.roblox.com/asset/?id=180435571"
local idleTrack = animator:LoadAnimation(idleAnim)

local walkAnim = Instance.new("Animation")
walkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
local walkTrack = animator:LoadAnimation(walkAnim)

idleTrack:Play()

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not walkTrack.IsPlaying then
			idleTrack:Stop()
			walkTrack:Play()
		end
	else
		if not idleTrack.IsPlaying then
			walkTrack:Stop()
			idleTrack:Play()
		end
	end
end)

end

local function spawnRig()
local chosenFolder = math.random(1,2) == 1 and retroFolder or notRetroFolder
local rig = chosenFolder:GetChildren()[1]
if not rig then
warn(“No rig found in chosen folder”)
return
end

local newRig = rig:Clone()
newRig.Parent = Workspace

local hrp = newRig:WaitForChild("HumanoidRootPart") :: Part
local humanoid = newRig:WaitForChild("Humanoid") :: Humanoid

hrp.Anchored = false
humanoid.WalkSpeed = 4
humanoid.AutoRotate = true

addAnimate(newRig)

hrp.CFrame = CFrame.new(spawnPart.Position + Vector3.new(0, hrp.Size.Y/2, 0))

local stopCenter = stopPart.Position + Vector3.new(0, 0, 1)
humanoid:MoveTo(stopCenter)

local conn
conn = RunService.Heartbeat:Connect(function()
	local distance = (hrp.Position - stopCenter).Magnitude

	if distance < 0.5 then
		conn:Disconnect()

		humanoid:Move(Vector3.new(0,0,0), false)
		humanoid.PlatformStand = true
		humanoid.AutoRotate = false
		hrp.Anchored = true

		local look = hrp.CFrame.LookVector
		local rotatedLook = Vector3.new(-look.Z, 0, look.X)
		hrp.CFrame = CFrame.new(stopCenter, stopCenter + rotatedLook)

		for _, part in ipairs(newRig:GetDescendants()) do
			if part:IsA("BasePart") and part ~= hrp then
				local weld = Instance.new("WeldConstraint")
				weld.Part0 = hrp
				weld.Part1 = part
				weld.Parent = part
			end
		end
	end
end)

end

spawnRig()

oops i formatted it wrong here’s the script

local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local retroFolder = Workspace:WaitForChild("RetroSlops")
local notRetroFolder = Workspace:WaitForChild("NotRetroSlops")
local spawnPart = Workspace:WaitForChild("SpawnPart")
local stopPart = Workspace:WaitForChild("StopPart")

local function addAnimate(rig)
	local humanoid = rig:FindFirstChild("Humanoid")
	if not humanoid then return end

	local animator = humanoid:FindFirstChildOfClass("Animator")
	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local idleAnim = Instance.new("Animation")
	idleAnim.AnimationId = "http://www.roblox.com/asset/?id=180435571"
	local idleTrack = animator:LoadAnimation(idleAnim)

	local walkAnim = Instance.new("Animation")
	walkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
	local walkTrack = animator:LoadAnimation(walkAnim)

	idleTrack:Play()

	humanoid.Running:Connect(function(speed)
		if speed > 0 then
			if not walkTrack.IsPlaying then
				idleTrack:Stop()
				walkTrack:Play()
			end
		else
			if not idleTrack.IsPlaying then
				walkTrack:Stop()
				idleTrack:Play()
			end
		end
	end)
end

local function spawnRig()
	local chosenFolder = math.random(1,2) == 1 and retroFolder or notRetroFolder
	local rig = chosenFolder:GetChildren()[1]
	if not rig then
		warn("No rig found in chosen folder")
		return
	end

	local newRig = rig:Clone()
	newRig.Parent = Workspace

	local hrp = newRig:WaitForChild("HumanoidRootPart") :: Part
	local humanoid = newRig:WaitForChild("Humanoid") :: Humanoid

	hrp.Anchored = false
	humanoid.WalkSpeed = 4
	humanoid.AutoRotate = true

	addAnimate(newRig)

	hrp.CFrame = CFrame.new(spawnPart.Position + Vector3.new(0, hrp.Size.Y/2, 0))

	local stopCenter = stopPart.Position + Vector3.new(0, 0, 1)
	humanoid:MoveTo(stopCenter)

	local conn
	conn = RunService.Heartbeat:Connect(function()
		local distance = (hrp.Position - stopCenter).Magnitude

		if distance < 0.5 then
			conn:Disconnect()

			humanoid:Move(Vector3.new(0,0,0), false)
			humanoid.PlatformStand = true
			humanoid.AutoRotate = false
			hrp.Anchored = true

			local look = hrp.CFrame.LookVector
			local rotatedLook = Vector3.new(-look.Z, 0, look.X)
			hrp.CFrame = CFrame.new(stopCenter, stopCenter + rotatedLook)

			for _, part in ipairs(newRig:GetDescendants()) do
				if part:IsA("BasePart") and part ~= hrp then
					local weld = Instance.new("WeldConstraint")
					weld.Part0 = hrp
					weld.Part1 = part
					weld.Parent = part
				end
			end
		end
	end)
end

spawnRig()

Oh, I think I see the issue… do the rotation before anchoring the part. Right now you’re anchoring first, then trying to rotate, which doesn’t work. Move the rotation line above the hrp.Anchored = true line.

Didn’t seem to work too

local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local retroFolder = Workspace:WaitForChild("RetroSlops")
local notRetroFolder = Workspace:WaitForChild("NotRetroSlops")
local spawnPart = Workspace:WaitForChild("SpawnPart")
local stopPart = Workspace:WaitForChild("StopPart")

local function addAnimate(rig)
	local humanoid = rig:FindFirstChild("Humanoid")
	if not humanoid then return end

	local animator = humanoid:FindFirstChildOfClass("Animator")
	if not animator then
		animator = Instance.new("Animator")
		animator.Parent = humanoid
	end

	local idleAnim = Instance.new("Animation")
	idleAnim.AnimationId = "http://www.roblox.com/asset/?id=180435571"
	local idleTrack = animator:LoadAnimation(idleAnim)

	local walkAnim = Instance.new("Animation")
	walkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354"
	local walkTrack = animator:LoadAnimation(walkAnim)

	idleTrack:Play()

	humanoid.Running:Connect(function(speed)
		if speed > 0 then
			if not walkTrack.IsPlaying then
				idleTrack:Stop()
				walkTrack:Play()
			end
		else
			if not idleTrack.IsPlaying then
				walkTrack:Stop()
				idleTrack:Play()
			end
		end
	end)
end

local function spawnRig()
	local chosenFolder = math.random(1,2) == 1 and retroFolder or notRetroFolder
	local rig = chosenFolder:GetChildren()[1]
	if not rig then
		warn("No rig found in chosen folder")
		return
	end

	local newRig = rig:Clone()
	newRig.Parent = Workspace

	local hrp = newRig:WaitForChild("HumanoidRootPart") :: Part
	local humanoid = newRig:WaitForChild("Humanoid") :: Humanoid

	hrp.Anchored = false
	humanoid.WalkSpeed = 4
	humanoid.AutoRotate = true

	addAnimate(newRig)

	hrp.CFrame = CFrame.new(spawnPart.Position + Vector3.new(0, hrp.Size.Y/2, 0))

	local stopCenter = stopPart.Position + Vector3.new(0, 0, 1)
	humanoid:MoveTo(stopCenter)

	local conn
	conn = RunService.Heartbeat:Connect(function()
		local distance = (hrp.Position - stopCenter).Magnitude

		if distance < 0.5 then
			conn:Disconnect()

			humanoid:Move(Vector3.new(0,0,0), false)
			humanoid.PlatformStand = true
			humanoid.AutoRotate = false

			hrp.CFrame = CFrame.new(hrp.Position) * CFrame.Angles(0, math.rad(90), 0)

			hrp.Anchored = true

			for _, part in ipairs(newRig:GetDescendants()) do
				if part:IsA("BasePart") and part ~= hrp then
					local weld = Instance.new("WeldConstraint")
					weld.Part0 = hrp
					weld.Part1 = part
					weld.Parent = part
				end
			end
		end
	end)
end

spawnRig()

The main issue is timing and order… When you anchor first then rotate, the physics locks the part so the rotation wont apply. Rotate the humanoid root part first using CFrame.Angles or LookVector then anchor it!



Also make sure AutoRotate is off before rotation otherwise the humanoid will override your rotation. Finally weld other parts after the rotation so everything stays aligned.

Hope this helped!!!