Hello, I’m DarkBegin, I’m trying to make a script linked to my dialog script where the NPC turns towards me.
I want him turning in Y-axis only, actually, it doesn’t work, it’s broken. If I’m in front of him, the NPC lean towards me like Michael Jackson.
local cf = npc:GetPrimaryPartCFrame()
local newCf = CFrame.new(cf.Position.Y, game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
npc:SetPrimaryPartCFrame(newCf)
local cf = npc:GetPrimaryPartCFrame()
local newCf = CFrame.new(cf.Position.Y, game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
npc:SetPrimaryPartCFrame(newCf)
CFrame.new(from, toward) will create a CFrame located at from that faces toward toward.
First off, that error is entirely true; you are trying to make the figure face from a number toward another another position. Where is the number? A number is not anywhere, it’s just a number. You can’t find the number 22.75768 anywhere in the world, it is just an amount.
You probably meant to make it face from cf.Position instead of cf.Position.Y, but that creates the situation you had in your post.
The solution is to make the Y axes of both positions the same, so that it always acts as if the target were standing beside the figure, even if it’s jumping above it.
local cf = npc:GetPrimaryPartCFrame()
local newCf = CFrame.new(cf.Position, Vector3.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position.X, cf.Position.Y, game.Players.LocalPlayer.Character.HumanoidRootPart.Position.Z))
npc:SetPrimaryPartCFrame(newCf)
-- Cleaned up, works exactly the same
local from = npc:GetPrimaryPartCFrame().Position
local to = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
local newCf = CFrame.lookAt(from, Vector3.new(from, Vector3.new(to.X, from.Y, to.Z)))