Trouble with rotating lobby screen

Hello. I’ve been working on making a rotating lobby screen, but all of my scripts are inconsistent and only work every once in a while. Any suggestions on how to approach this? Here is my current script:

local button = script.Parent
local blur = game.Lighting.Blur
local GUI = button.Parent
local cam = workspace.CurrentCamera

blur.Enabled = true

repeat wait()
	cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable

function updateCamera()
	cam.CFrame = game.Workspace.CameraView.CFrame
end

game:GetService("RunService"):BindToRenderStep("camera", 1, updateCamera)

button.MouseButton1Click:Connect(function()
	GUI:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1)
	wait(1)
	GUI:Destroy()
	blur.Enabled = false
	game:GetService("RunService"):UnbindFromRenderStep("camera")
	repeat wait()
		cam.CameraType = Enum.CameraType.Custom
	until cam.CameraType == Enum.CameraType.Custom
end)

The camera is supposed to return to the player after the play button is clicked, but my script only executes that half of the time.

Here is a video of it messing up:

1 Like

From the script you provided, it appears that you’re using a repeat loop combined with wait() to check if the camera type has changed. However, this approach might lead to inconsistent behavior and occasional failures due to the timing and synchronization of the events.

To improve the reliability and consistency of your script, I recommend using the RenderStepped event instead of the repeat loop with wait(). Here’s an updated version of your script that utilizes the RenderStepped event:

local button = script.Parent
local blur = game.Lighting.Blur
local GUI = button.Parent
local cam = workspace.CurrentCamera

local function updateCamera()
	cam.CFrame = game.Workspace.CameraView.CFrame
end

local function resetCamera()
	cam.CameraType = Enum.CameraType.Custom
	game:GetService("RunService"):UnbindFromRenderStep("camera")
end

button.MouseButton1Click:Connect(function()
	GUI:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1)
	wait(1)
	GUI:Destroy()
	blur.Enabled = false
	
	cam.CameraType = Enum.CameraType.Scriptable
	game:GetService("RunService"):BindToRenderStep("camera", Enum.RenderPriority.Camera.Value, updateCamera)
	
	game:GetService("RunService").RenderStepped:Wait() -- Wait for the first frame update
	
	game:GetService("RunService").RenderStepped:Connect(function()
		if cam.CameraType == Enum.CameraType.Custom then
			resetCamera()
		end
	end)
end)

In this updated script, the repeat loop with wait() is replaced with the RenderStepped event. After the play button is clicked, it changes the camera type to Scriptable and binds the updateCamera function to the RenderStep event. It also waits for the first frame update to ensure synchronization.

Then, the RenderStepped event is connected to a function that checks if the camera type has changed back to Custom. Once the camera type is Custom, it calls the resetCamera function, unbinds the RenderStep event, and resets the camera type.

Using the RenderStepped event ensures that the camera update and type check are performed reliably on every frame, increasing the consistency of your rotating lobby screen.

1 Like

I should have been a bit clearer, but the game starts with the rotating of the lobby screen. What I’m struggling with is resetting the camera to normal when the play button is clicked. I hope that makes more sense.

I was actually able to move the ‘BindToRenderStep’ line out of the mouse-button function to run it before the button is pressed. Thanks for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.