Camera sometimes breaks

So I created a menu screen that makes the CameraType “Scriptable”. However, the CameraType is not always set to “Scriptable”. There are no errors in the output. I also used repeat to ensure that it was set to scriptable, but it still didn’t work. Here’s my code:

local cframe = script.CameraCFrame.Value
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

repeat
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
task.wait()
until game.Workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable

game.Workspace.CurrentCamera.CFrame = cframe

while task.wait(0.01) do
game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(0, 0.1/100, 0)
end
1 Like

Have you tried removing the task.wait()

Wouldn’t removing task.wait() result in a crash?

2 Likes

Unfortunately, this is Roblox.

You need to wait 2 seconds for the client to load in. Add a wait(2) after the local Character statement.

A Localscript in StarterGui

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable 
while task.wait(0.01) do
	camera.CFrame *= CFrame.Angles(0, 0.1/100, 0)
end

Comes out as a nice little camera rotation …
Also the camera will not say Scriptable after the call it will say Custom.

I don’t recommend waiting 0.01 seconds. I would rather use TweenService or something similar, because this will slow down the server or whatever is using it.

I agree … never ever use wait(0.01) like that.

local rs=game:GetService("RunService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable 
while true do rs.Stepped:Wait()
	camera.CFrame *= CFrame.Angles(0, 0.1/100, 0)
end

Much better and will work with your game not fight it.

Thank you very much! I was about to ask whether I should use RunService

That Stepped:Wait() is gold! Not only will it work but it will mesh with what’s going on atm.
Could ask for a better fast wait! That is the equivalent of the Assembler EOS or Last line call. Basically waiting till the screen is at the bottom of the current frame wipe then triggering. Very nicely keeping everything in sync.

If I was on the client, I would use RenderStepped. For camera movements, I would bind the event to RunService, after Roblox does their thing with the camera.

Use it in ReplicatedFirst, and begin the function when the CurrentCamera.Position doesnt return nil

Like this?

function RotateCamera()
	game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(0, 0.1/100, 0)
end

RunService:BindToRenderStep("RotateCamera", 200, RotateCamera)

I wouldn’t be too sure, but I know there’s an Enum thing that you can do and bind it to the Camera value + 1. This will make it go after Roblox does their stuff with the camera. There’s several examples of this but I don’t have time to look it up right now.

Wow that is sweet! … like this:

-- in ReplicatedStorage as a Localscript

function RotateCamera()
	game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(0, 0.1/100, 0)
end
RotateCamera()
game:GetService("RunService"):BindToRenderStep("RotateCamera", 200, RotateCamera)

Good stuff NobleBuild! But how do you stop it and remove the bind? Also wouldn’t everyone see that at the same time?

I think you would do this

function RotateCamera()

game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(0, 0.1/100, 0)

end

RunService:BindToRenderStep("RotateCamera", Enum.RenderPriority.Camera.Value - 1, RotateCamera)

local success, err = pcall(RunService:UnbindFromRenderStep("RotateCamera"))

if not success then

warn(err)

end

Also I don’t think that everyone would see it since it is on the client.

Never knew about BindToRenderStep and UnbindFromRenderStep.
Oh the possibilities :wink:

Ya it is a LocalScript …

1 Like

I would do exactly that, but I would add one to the priority. We want to do camera stuff after Roblox does, but I wouldn’t know the Enum values and how they’re ordered.

1 Like