I'm making a tycoon with AI miners that will go mine ores for the player. I have a Union with two values (Hits, OreValue) and two parts (MinePart, Low / Medium / High) I've made a script that whenever an NPC touches an ore, it goes to a position and plays an animation. I have two problems with this code. 1. I don't know how to orient the humanoid to face the ore when mining it. 2. The script ignores some of the lines of code. Here's the code:
-- Low, Medium or High refers to the ore's quality
-- Script does the repeat until loop once sometimes, and doesn't make sure the character is not a player
local blocks = workspace:WaitForChild('Blocks') -- The folder containing all mine-able ores
local anim = script.Animation
local deb = true
function getRandomChild(model)
local children = model:GetChildren()
local child = children[math.random(1, #children)]
return child
end
for i,v in pairs(blocks:GetChildren()) do
if v:FindFirstChild('OreValue') and v:FindFirstChild('Hits') and v:FindFirstChild('MinePart') then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and deb == true and not game.Players:FindFirstChild(hit.Parent.Name) and v:FindFirstChild('Low') or v:FindFirstChild('Medium') or v:FindFirstChild('High') and hit:IsA('MeshPart') then
deb = false
local loadedAnim = hit.Parent.Humanoid:LoadAnimation(anim)
local hits = v.Hits
local regHitsValue = hits.Value -- Original hits value, this is here to make sure that the hits value can return to its original value when the ore finishes being mined
hit.Parent:MoveTo(v.MinePart.Position) -- Moves the character to the MinePart, doesn't orient the character
wait(.1)
hit.Parent['HumanoidRootPart'].Anchored = true -- Makes sure that the character stays in one place for the animation
repeat
loadedAnim:Play()
wait(loadedAnim.Length)
hits.Value = hits.Value - 1
until hits.Value <= 0
loadedAnim:Stop()
hit.Parent['HumanoidRootPart'].Anchored = false
hits.Value = regHitsValue
if v:FindFirstChild('Low') then
v.Low:Destroy()
elseif v:FindFirstChild('Medium') then
v.Medium:Destroy()
elseif v:FindFirstChild('High') then
v.High:Destroy()
end
deb = true
end
end)
end
end
If you have any answers or at least some tips, please help! Thanks for taking some time to look at my question. If you'd like any additional information, please ask!

3 comments
For the orientation you should use CFrame, as that includes position AND orientation. Or you can use CFrame.LookVector, which is the way the front of the part is looking at.
Okay thank you
I used CFrame, yet it didn't orient the humanoid correctly, and LookVector cannot be assigned