I have this NPC that when I'm near it and I press "E," then it's supposed to lerp the camera to face the NPC. It does face the camera where I want it, except it instantly puts it there instead of doing it smootly/lerping it.
Here is the part of the script with the lerp:()
Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E and Detected.Value == true then
DetectedNPC == NPC then --Chatting.Value == true then
--for i, NPC in pairs(NPCs:GetChildren()) do
local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")
if Humanoid and HMR then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 0
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower = 0
end
end
end)
And here is the full script:
--//Services
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Players1 = game:GetService("Players")
--//Main Varibles
local Values = script.Parent.Values
local DetectedNPC = Values.DetectedNPC
local Detected = Values.Detected
local Chatting = Values.Chatting
local Skip = Values.Skip
local Exit = Values.Exit
DetectedNPC = nil
Detected.Value = false
Chatting.Value = false
Skip.Value = false
Exit.Value = false
--//Player
local Player = Players1.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local Gui = script.Parent
local Sounds = Gui.Sounds
local PromptLable = Gui.PromptLable:Clone()
local LineLable = Gui.LineLable
--//Character
local Character1 = Player.Character or Player.CharacterAdded:Wait()
local CharHMR = Character1:WaitForChild("HumanoidRootPart")
--//NPC
local NPCs = game.Workspace:WaitForChild("NPCs")
--//Functions
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.X then
if Chatting.Value == true then
Skip.Value = true
local PromptLabler = DetectedNPC:WaitForChild("PromptLabler")
Sounds.ButtonConfirm:Play()
PromptLabler:WaitForChild("PromptLable").PromptLable.Visible = true
Camera.CameraType = Enum.CameraType.Custom
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 16
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower = 50
end
end
end)
script.Parent.LineLable.Close.MouseButton1Click:connect(function()
if Chatting.Value == true then
Exit.Value = true
Sounds.ButtonConfirm:Play()
local PromptLabler = DetectedNPC:FindFirstChild("PromptLabler")
PromptLabler:WaitForChild("PromptLable").PromptLable.Visible = true
Camera.CameraType = Enum.CameraType.Custom
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 16
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower = 50
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if Detected.Value == true then
local Lines = DetectedNPC:FindFirstChild("Lines")
if Lines then
Sounds.ButtonConfirm:Play()
Chatting.Value = true
Detected.Value = false
LineLable.Text = " "
--PromptLable:TweenSize(UDim2.new(0,0,0,0), "Out", "Linear",.2)
LineLable:TweenPosition(UDim2.new(0.21, 0,0.701, 0), "In", "Linear",.2)
local PromptLabler = DetectedNPC:FindFirstChild("PromptLabler")
PromptLabler:WaitForChild("PromptLable").PromptLable.Visible = false
wait(.5)
for i, Line in pairs(Lines:GetChildren()) do
local Text = Line.Value
for i = 1, #Text do
LineLable.Text = string.sub(Text, 1, i)
Sounds.Talk:Play()
if Skip.Value == true then
Skip.Value = false
LineLable.Text = Text
break
end
if Exit.Value == true then
break
end
wait(.07)
end
if Exit.Value == true then
Exit.Value = false
break
end
repeat wait() until Skip.Value == true or Exit.Value == true
Skip.Value = false
end
Exit.Value = false
Skip.Value = false
--PromptLable:TweenSize(UDim2.new(0,0,0,0), "Out", "Linear", .2)
LineLable:TweenPosition(UDim2.new(0.21, 0,1.2, 0), "Out", "Linear",.2)
wait(0.5)
Chatting.Value = false
Detected.Value = false
end
end
end
end)
--//MainLoop
RunService.RenderStepped:Connect(function()
if Character1.Humanoid.Health <= 0 then
local PromptLabler = DetectedNPC:FindFirstChild("PromptLabler")
PromptLabler:WaitForChild("PromptLable").PromptLable.Visible = true
end
if Detected.Value == false and Chatting.Value == false then
for i, NPC in pairs(NPCs:GetChildren()) do
local Humanoid = NPC:FindFirstChild("Humanoid")
local HMR = NPC:FindFirstChild("HumanoidRootPart")
if Humanoid and HMR then
if (HMR.Position - CharHMR.Position).magnitude < 15 then
Detected.Value = true
DetectedNPC = NPC
--PromptLable:TweenSize(UDim2.new(0,60,0,60), "In", "Linear",.2)
print(DetectedNPC.Name)
end
end
end
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E and Detected.Value == true then --and DetectedNPC == NPC then --Chatting.Value == true then
--for i, NPC in pairs(NPCs:GetChildren()) do
local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")
if Humanoid and HMR then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 0
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").JumpPower = 0
end
end
end)
if Detected.Value == true and Chatting.Value == false then
local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")
local UpperTor = DetectedNPC:FindFirstChild("UpperTorso")
--local PromptLabler = DetectedNPC:FindFirstChild("PromptLabler")
if Humanoid and HMR then
if (HMR.Position - CharHMR.Position).magnitude > 15 then
Detected.Value = false
DetectedNPC = nil
--PromptLable:TweenSize(UDim2.new(0,0,0,0), "Out", "Linear",.2)
print("No Longer Detected NPC")
else
local WTSP = Camera:WorldToScreenPoint(HMR.Position)
--PromptLable.Position = UDim2.new(0,WTSP.X, 0, WTSP.Y)
--PromptLable:Destroy()
--HMR:WaitForChild("PromptLable").PromptLable.Visible = false
end
end
end
end)
Help would be appreciated thanks.

2 comments
Can you at least provide the portion that's not working? (i.e, the actual lerp function)
I did but might be hard to see it's this: Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)