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

The script makes character look glitchy?

Asked by 6 years ago

I wanted to set a camera that is behind the character (like third person shooter camera) And it worked... kinda. The character movement isnt smooth and so is the camera. Please help if i miss something in the script.

game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Scriptable"
local target = game.Players.LocalPlayer.Character.Humanoid.Torso
local camera = workspace.CurrentCamera
while wait() do
    camera.CoordinateFrame = CFrame.new(target.Position)
                            * CFrame.new(2, 2, 3)
end

1 answer

Log in to vote
-1
Answered by
Z_DC 104
6 years ago

It seems as you're using a while loop which is not fast enough to update on time. Try using the RunService to run that loop every render step or every frame like this:

game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Scriptable"
local target = game.Players.LocalPlayer.Character.Humanoid.Torso
local camera = workspace.CurrentCamera
game:GetService("RunService").RenderStepped:Connect(function()
    camera.CoordinateFrame = CFrame.new(target.Position)
                            * CFrame.new(2, 2, 3)
end)
Ad

Answer this question