I’ve ran into an issue with a feature I’m making. What I’m trying to do is make an NPC look in the general direction a player is going if they’re in a certain range. However, when this is done, the NPC goes into the ground for some unknown reason. I haven’t been able to really find a good solution for this. Any help would be appreciated
For reference:
https://gyazo.com/3cd9a496e644b2a4d2e9b6154ec9cce5
Here’s the code for it:
RunService.RenderStepped:Connect(function()
for _, v: Model in workspace:GetChildren() do
if v:IsA("Model") and v.Name == "Dummy" and v:FindFirstChild("HumanoidRootPart") then
local ROOT: BasePart = v:FindFirstChild("HumanoidRootPart")
if (HumanoidRootPart.Position - ROOT.Position).Magnitude > 15 then
return
end
TweenService:Create(ROOT, TweenInfo.new(0.5), {CFrame = CFrame.lookAt(
Vector3.new(ROOT.Position.X, 0, ROOT.Position.Z),
Vector3.new(HumanoidRootPart.Position.X, 0, HumanoidRootPart.Position.Z)
)
}):Play()
end
end
end)