Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I have a focus script but cant figure a way to make the CFrame work without glitches?

So I have this script that make the player focuses on an npc but for some reason it freak when in its on the client. in the server it works just fine. What Can in do to fix it?

Video https://vimeo.com/721773897

Code:

		local Camera = workspace.CurrentCamera

		local Goal = workspace.Enemies:FindFirstChild(chainedEnemyGlobal)

		while true do
		   wait(0.01)
		   Camera.CameraType = Enum.CameraType.Scriptable
		   Camera.CameraSubject = player.Character.Head
		   character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position) * CFrame.Angles(0,Vector3.new(CFrame.new(character.HumanoidRootPart.Position, Goal.Head.Position):ToOrientation()).Y,0)	
		end

1 answer

✓ Accepted answer

I don't know if this will solve it, but instead of using a while loop, you can use "RunService.RenderStepped" instead. Your code would look like this with it.

local Camera = workspace.CurrentCamera

local Goal = workspace.Enemies:FindFirstChild(chainedEnemyGlobal)

local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	Camera.CameraType = Enum.CameraType.Scriptable
   	Camera.CameraSubject = player.Character.Head
   	character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position) * CFrame.Angles(0,Vector3.new(CFrame.new(character.HumanoidRootPart.Position, Goal.Head.Position):ToOrientation()).Y,0)  
end)

1 comment

0

Yeah It Worked. Finally

This discussion is preserved as it was. New answers, comments, and votes are closed.