2D Lock-On Script Problem

Hello there!
I am currently working on a 2D fighting game, and i am currently making a Lock-On Script. I’ve already locked the character rotation, but i am trying to make the character look at the enemy.

The script so far:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local enemy = workspace.Enemy.Value
local camera = workspace.CurrentCamera

game:GetService("RunService").RenderStepped:Connect(function()
	local pitch, yaw, roll = camera.CFrame:ToEulerAnglesYXZ()
	character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.CFrame.p) * CFrame.Angles(0,yaw-90,0)
end)

Heres a video of the problem:
robloxapp-20200801-1938519.wmv (1.2 MB)

If you could help me with this, i would be grateful. :slight_smile:

1 Like

Never mind i found out about it myself.