Hi. I'm trying to make an enemy lock on script, I've got it working for the most part but this (Badly made) part makes the player fly off into the distance when you jump near a locked on enemy. Here's the part that's causing trouble:

startLockOnService = coroutine.create(function()
	game:GetService("RunService").RenderStepped:connect(function()
		if lockedOnEnemy ~= nil then --This isn't important
			player.HumanoidRootPart.CFrame = CFrame.new(player.HumanoidRootPart.Position, lockedOnEnemy.HumanoidRootPart.Position) --This rotates the players HumanoidPart to face the enemies HumanoidPart
			camera.CoordinateFrame = CFrame.new((player.HumanoidRootPart.CFrame * CFrame.new(0, 7, 15)).p, lockedOnEnemy.HumanoidRootPart.Position) --And this puts the camera behind and above the player and faces the enemies humanoid
		else
			coroutine.yield()
		end
	end)
end)

I kind of know what's wrong, I shouldn't be setting the HumanoidRootPart position on the player, but I don't see any other way of doing it without making the camera shake a little, because the camera is using the players CFrame to move it behind the player. Any help would be appreciated, thanks

2 comments

0

Code block please.

0

Sorry, first time on this site. I added the codeblock, but it's a bit glitched I think