How to bring back camera to the player after making camera scriptable

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to bring camera back after clicking a button.

  2. What is the issue? The camera is not bringing back after I clicked button.

External Media

3. What solutions have you tried so far? I searched about this in Devloper hub but I can’t figure out solution

This is the local script in the button.


script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.RemoteEvents.Start:FireServer()
	game.ReplicatedStorage.BGMFolder.BreakingThrough:Stop()

	script.Parent.Sentaku:Play()
	
	script.Parent.Parent.Enabled = false
	
	wait(2)
	
	local Tween = TweenService:Create(script.Parent.Parent.Parent.LoadGui.Bg, TweenInfo.new(1), {BackgroundTransparency = 0})		
	Tween:Play()

	local cam = workspace.CurrentCamera

	repeat

		wait()
		cam.CameraType = Enum.CameraType.Fixed

	until 	

	cam.CameraType == Enum.CameraType.Fixed

	cam.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame

	wait(3)
	
	script.Parent.Parent.Parent.LoadGui.Bg.Horn:Play()
	script.Parent.Parent.Parent.LoadGui.Bg.TextLabel.Text = "DAY 1"
	
	wait(3)
	
	local Tween2 = TweenService:Create(script.Parent.Parent.Parent.LoadGui.Bg, TweenInfo.new(1), {BackgroundTransparency = 1})		
	Tween2:Play()
	


	
	wait(2)
	
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

	script.Parent.Parent.Parent.LoadGui.Bg.TextLabel.Text = ""


end)

This is the local script to make camera focus on the house at the first part.

button.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.BGMFolder.BreakingThrough:Play()
	
	local cam = workspace.CurrentCamera
	local camPart = game.Workspace.Cameras:WaitForChild("TitleScreen")
	local mouse = game:GetService("Players").LocalPlayer:GetMouse()

	--// Set cam
	repeat
		wait()
		cam.CameraType = Enum.CameraType.Scriptable
	until
	cam.CameraType == Enum.CameraType.Scriptable

	cam.CFrame = camPart.CFrame
	--// Move cam
	local maxTilt = 20
	game:GetService("RunService").RenderStepped:Connect(function()
		cam.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)

end)


There is no error occured.

The problem was because I was Chaging Camera CFrame to the block at

game:GetService("RunService").RenderStepped:Connect(function()
		cam.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)

So I added (if A == 1 then … end) so I could control this activities by changing value of A!

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