AlignOrientation.MaxTorque error

Hi, I want to make my units look at the target when attacking so I’m using AlignOrientation.
Error: -value of type Vector3 cannot be converted to a number
Code:

function unit.Spawn(player, unitName, pos)
	local unitExists = rs.UnitsFolder:FindFirstChild(unitName)
	local profile = Manager.Profiles[player]
	local money = profile.Data.Money
	local price = getUnitPrice(unitName)

	if not unitExists then return end
	if not profile then return end

	if UNIT_COUNT >= MAX_UNIT_COUNT then
		rs.Remotes.UpdateUnits:FireClient(player, UNIT_COUNT, FARM_UNIT_COUNT, "normal")
		return
	end

	if price > money then
		rs.Remotes.NoMoney:FireClient(player)
		return
	end

	local isFarmUnit = table.find(farmUnits, unitName) ~= nil
	if isFarmUnit and FARM_UNIT_COUNT >= MAX_FARM_UNIT_COUNT then
		rs.Remotes.UpdateUnits:FireClient(player, UNIT_COUNT, FARM_UNIT_COUNT, "farm")
		return
	end

	Manager.AdjustMoney(player, -price)
	local newUnit = unitExists.Model:Clone()	
	newUnit.PrimaryPart.CFrame = pos
	newUnit.Parent = workspace.Units
	newUnit.Name = unitName.."_Model"
	newUnit.PrimaryPart:SetNetworkOwner(nil)
	
	local orientation = Instance.new("AlignOrientation")
	print(newUnit, newUnit.Gnome, newUnit.Gnome.HumanoidRootPart)
	orientation.Parent = newUnit.Gnome.HumanoidRootPart
	orientation.MaxTorque = Vector3.new(1000000, 1000000, 1000000)
	orientation.CFrame = newUnit.Gnome.HumanoidRootPart.CFrame

	if isFarmUnit then
		FARM_UNIT_COUNT += 1
		rs.Remotes.UpdateUnits:FireClient(player, UNIT_COUNT, FARM_UNIT_COUNT, "farm")
	else
		UNIT_COUNT += 1
		rs.Remotes.UpdateUnits:FireClient(player, UNIT_COUNT, FARM_UNIT_COUNT, "normal")
	end

	coroutine.wrap(unit.Attack)(newUnit)

	for _, obj in ipairs(newUnit:GetDescendants()) do
		if obj:IsA("BasePart") then
			obj.CollisionGroup = "Unit"
			task.wait(1)
			obj.Anchored = true
		end
	end
end

I’ve tried looking up on forum / documentation, but nothing, I tried using BodyGyro but well, it’s deprecated so I switched on AlignOrientation. I also tried using lower numbers instead of 1m but error stays the same.

Any help will be appreciated, if you even have other ways to do it let me know!

align orientation max torque describes the magnitude of the max torque, it takes a number as a value not a vector3
try this instead:
orientation.MaxTorque = 1000000

1 Like

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