Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
VAnkata20 135
2 years ago
Edited 2 years ago

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

Log in to vote
1
Answered by 2 years ago

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)
0
Yeah It Worked. Finally VAnkata20 135 — 2y
Ad

Answer this question