applying new camera cframe every frame is pausing gameplay and completely messing up my game
video:
code:
-- services
local run = game:GetService("RunService")
-- references
local camera = workspace.CurrentCamera
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")
-- functions
local function update()
if camera then -- camera exists
if _G.cl_settings.flags["cameraLock"] and not _G.menuScreen then -- camera lock is enabled
local zoom = ((root.Position + Vector3.new(0, 1.5, 0)) - camera.CFrame.Position).Magnitude -- how far the player has zoomed in
local cameraCFrame = CFrame.new(Vector3.new(root.Position.X, root.Position.Y + 1.5 + zoom, root.Position.Z), root.Position)
camera.CFrame = cameraCFrame -- apply camera fixed value
end
else -- camera reference does not exist
camera = workspace.CurrentCamera -- apply camera reference
end
end
-- wait until settings have been loaded
repeat task.wait() until _G.cl_settings
-- update camera every frame
run.RenderStepped:Connect(update)
the _G values are controlled by other scripts, _G.cl_settings is the directory for the settings library i made, _G.cl_settings.flags is a table containing the values all settings, _G.menuScreen determains if the menuscreen seen in the start of the video is currently open.
RunService.RenderStepped:Connect(func) - yeah its better than while true do but try this:
while true do
update()
wait()
end
Maybe some perfomance issue when much while true do but maybe it will stop pause game
BUT
if you dont want to use that, try to add wait() or task.wait() on the end of update() function. Maybe it will help you some, if not try while true do. Maybe both won’t help you… but i tried
Heyya little guy, i got good news for you.
The problem in your script is Zoom value, idk how but its all problem.
i found solution, its use mouse.WheelForward/Backward and cusom zoom value
-- services
local run = game:GetService("RunService")
-- references
local camera = workspace.CurrentCamera
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local cameraLocked = true
camera.CameraType = Enum.CameraType.Scriptable
local menuScreen = false
-- functions
local zoom = 20
local function update()
if camera then -- camera exists
if cameraLocked == true and menuScreen == false then -- camera lock is enabled
local cameraCFrame = CFrame.new(Vector3.new(root.Position.X, root.Position.Y + zoom, root.Position.Z), root.Position)
camera.CFrame = cameraCFrame -- apply camera fixed value
end
else -- camera reference does not exist
camera = workspace.CurrentCamera -- apply camera reference
end
end
mouse.WheelForward:Connect(function()
if not (zoom < 8) then
zoom -= 1
print(zoom)
else
zoom = 8
end
end)
mouse.WheelBackward:Connect(function()
if not (zoom > 39) then
zoom += 1
print(zoom)
else
zoom = 39
end
end)
-- wait until settings have been loaded
--repeat task.wait() until _G.cl_settings
-- update camera every frame
run.RenderStepped:Connect(update)
BUT
I found that if zoom value is 41 and greater, then problem is staying, im really dont know why.
-- services
local run = game:GetService("RunService")
-- references
local camera = workspace.CurrentCamera
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")
-- functions
local function update()
if camera then -- camera exists
local zoom = ((root.Position + Vector3.new(0, 1.5, 0)) - camera.CFrame.Position).Magnitude -- how far the player has zoomed in
local cameraCFrame = CFrame.new(
Vector3.new(
root.Position.X,
root.Position.Y + 1.5 + zoom, -- 1.5 is the distance between the root and the head
root.Position.Z)
)
camera.CFrame = cameraCFrame * CFrame.Angles(math.rad(-90),0,0) -- apply camera fixed value
else -- camera reference does not exist
camera = workspace.CurrentCamera -- apply camera reference
end
end
-- update camera every frame
run.RenderStepped:Connect(update)