[SOLVED] Camera Movement Issue

Hello developers,

I made this script that will allow the user to click a button between camera views. I have that system done, however when I attach the camera to a vehicle and then go to a camera view the camera stays where it is at the time of pressing the button as shown in the video, here is the script aswell.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera


local CamFolder = script.Parent.CamFolder.Value
local GearCam = CamFolder.Gear
local TailCam = CamFolder.Tail
local TailWingLeftCam = CamFolder.TailWingLeft
local TailWingRightCam = CamFolder.TailWingRight



local GearButton = script.Parent.Frame.Gears
local TailButton = script.Parent.Frame.Tail
local TailWingLeftButton = script.Parent.Frame.TailWingLeft
local TailWingRightButton = script.Parent.Frame.TailWingRight
local Reset = script.Parent.Reset

local BlackFrame = script.Parent.Parent.Frame

GearButton.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end
	]]
	
	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable
	
	Camera.CFrame = GearCam.CFrame
	wait(2)
	

	--[[for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]

end)

TailButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

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

	Camera.CFrame = TailCam.CFrame
	wait(2)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingLeftButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

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

	Camera.CFrame = TailWingLeftCam.CFrame
	wait(2)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingRightButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable
	Camera.CFrame = TailWingRightCam.CFrame
	wait(2)
	
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

	
end)

script.Parent.Reset.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end]]

	repeat wait()
		Camera.CameraType = Enum.CameraType.Custom
	until Camera.CameraType == Enum.CameraType.Custom
	Camera.CFrame = Character.Head.CFrame
	wait(2)


--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]


end)

If anyone can provide a solution it’d be great. My theory of why the camera doesnt stay with the part, would be where it uses a CFrame, but i have no idea how i’d go around that.

it doesnt stay with the part cause your setting the cameras cframe once. user a renderstepped loop to keep setting the cframe

How would that look in a script exactly?

game:GetService("RunService").RenderStepped:Connect(function()
cam.CFrame = Part.CFrame
end)

but since your using a toggle your gonna to want to use BindToRenderStep that why you can disable/re enable

so

GearButton.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end
	]]
	
	game:GetService("RunService").BindToRenderStep:Connect(function()
		GearCam.CFrame = GearCam.CFrame
	end)
	

	--[[for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]

end)

no, look up how to use bind to render step and unbind RunService:BindToRenderStep

After reading it, this is what I managed to get constructed


local RunService = game:GetService("RunService")

GearButton.MouseButton1Click:Connect(function()


	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable
	RunService:BindToRenderStep("GearBinding",1, Camera.CFrame = GearCam.CFrame)
	
end)

However im quite confused as i get an error line underneath the = sign saying that it was expecting to close the line there, im realy confused on this so any help is appriciated, thank you.

you need to make a function that sets the cframe

local function SetCamCFrame()
Camera.CFrame = GearCam.CFrame
end
RunService:BindToRenderStep("GearBinding",1, SetCamCFrame)
1 Like

OMG your an absolute life saver, thank you so so so much.

1 Like

So I now have the issue where the camera bugs out and wont allow me to move it, but that I mean it just snaps back to view my character as normal as soon as I press the reset button on the gui, if you need a video I can take one but yea it wont allow me to move the camera without it snapping back to where it was.

The entire script now

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local RunService = game:GetService("RunService")


local CamFolder = script.Parent.CamFolder.Value
local GearCam = CamFolder.Gear
local TailCam = CamFolder.Tail
local TailWingLeftCam = CamFolder.TailWingLeft
local TailWingRightCam = CamFolder.TailWingRight



local GearButton = script.Parent.Frame.Gears
local TailButton = script.Parent.Frame.Tail
local TailWingLeftButton = script.Parent.Frame.TailWingLeft
local TailWingRightButton = script.Parent.Frame.TailWingRight
local Reset = script.Parent.Reset

local BlackFrame = script.Parent.Parent.Frame

local function SetGearCamCFrame()
	Camera.CFrame = GearCam.CFrame
end

local function SetTailCamCFrame()
	Camera.CFrame = TailCam.CFrame
end

local function SetLeftTailWingCamCFrame()
	Camera.CFrame = TailWingLeftCam.CFrame
end

local function SetRightTailWingCamCFrame()
	Camera.CFrame = TailWingRightCam.CFrame
end

GearButton.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end
	]]
	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable

	RunService:BindToRenderStep("GearBinding",1, SetGearCamCFrame)
	--[[for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]

end)

TailButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

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

	RunService:BindToRenderStep("TailBinding",1, SetTailCamCFrame)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingLeftButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

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

	RunService:BindToRenderStep("SetLeftTailWingBinding",1, SetLeftTailWingCamCFrame)

	wait(2)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingRightButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

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

	RunService:BindToRenderStep("SetRightTailWingBinding",1, SetRightTailWingCamCFrame)

	
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

	
end)

script.Parent.Reset.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end]]
	
	RunService:UnbindFromRenderStep(SetGearCamCFrame)
	RunService:UnbindFromRenderStep(SetTailCamCFrame)
	RunService:UnbindFromRenderStep(SetLeftTailWingCamCFrame)
	RunService:UnbindFromRenderStep(SetRightTailWingCamCFrame)
	
	repeat wait()
		Camera.CameraType = Enum.CameraType.Custom
	until Camera.CameraType == Enum.CameraType.Custom
	Camera.CFrame = Character.Head.CFrame
	wait(2)


--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]


end)

prob cause your repeat wait loops, try removing them and just set the cam type with a task.wait() dont use wait(), use task.wait()

Unfortunately, that didnt seem to fix the issue.

The camera only glitches out when I try move it.

idk its prob something with this line, but its like 1am for u
you can send the full code again and if i find anything ill edit it

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local RunService = game:GetService("RunService")


local CamFolder = script.Parent.CamFolder.Value
local GearCam = CamFolder.Gear
local TailCam = CamFolder.Tail
local TailWingLeftCam = CamFolder.TailWingLeft
local TailWingRightCam = CamFolder.TailWingRight



local GearButton = script.Parent.Frame.Gears
local TailButton = script.Parent.Frame.Tail
local TailWingLeftButton = script.Parent.Frame.TailWingLeft
local TailWingRightButton = script.Parent.Frame.TailWingRight
local Reset = script.Parent.Reset

local BlackFrame = script.Parent.Parent.Frame

local function SetGearCamCFrame()
	Camera.CFrame = GearCam.CFrame
end

local function SetTailCamCFrame()
	Camera.CFrame = TailCam.CFrame
end

local function SetLeftTailWingCamCFrame()
	Camera.CFrame = TailWingLeftCam.CFrame
end

local function SetRightTailWingCamCFrame()
	Camera.CFrame = TailWingRightCam.CFrame
end

GearButton.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end
	]]
	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable

	RunService:BindToRenderStep("GearBinding",1, SetGearCamCFrame)
	--[[for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]

end)

TailButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable

	RunService:BindToRenderStep("TailBinding",1, SetTailCamCFrame)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingLeftButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable

	RunService:BindToRenderStep("SetLeftTailWingBinding",1, SetLeftTailWingCamCFrame)

	wait(2)


	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

end)

TailWingRightButton.MouseButton1Click:Connect(function()
	wait(0.25)
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end

	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable

	RunService:BindToRenderStep("SetRightTailWingBinding",1, SetRightTailWingCamCFrame)

	
	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end

	
end)

script.Parent.Reset.MouseButton1Click:Connect(function()
	wait(0.25)
--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency - 0.05
		wait(0.1)
	end]]
	
	RunService:UnbindFromRenderStep(SetGearCamCFrame)
	RunService:UnbindFromRenderStep(SetTailCamCFrame)
	RunService:UnbindFromRenderStep(SetLeftTailWingCamCFrame)
	RunService:UnbindFromRenderStep(SetRightTailWingCamCFrame)
	
	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Custom
	until Camera.CameraType == Enum.CameraType.Custom
	Camera.CFrame = Character.Head.CFrame
	wait(2)


--[[	for i =1,18 do
		BlackFrame.Transparency = BlackFrame.Transparency + 0.05
		wait(0.1)
	end]]


end)

If you want the default camera system to take back over once the transition is complete, you net to set the CameraType back to ‘Custom’ or another trackable enum camera type.
Also, don’t forget to correctly set the CameraSubject.

As mentioned above you could also just go about manually setting the CFrame of the camera, but this means creating your own camera system, orientation and flow which may have a lot of problems down the line.

Again, if you want to restore the default camera settings, to just CameraType and CameraSubject

Thats what i’ve been trying to do with the script below setting the CameraType back to Custom,

	repeat task.wait()
		Camera.CameraType = Enum.CameraType.Custom
	until Camera.CameraType == Enum.CameraType.Custom
	Camera.CFrame = Character.Head.CFrame

Have you checked what CameraSubject is set to?

Camera.CameraSubject = Character.Head

I’ve just added that part below

Camera.CFrame = Character.Head.CFrame

And it still doesnt seem to fix the issue where you can move the camera around after clicking the reset button.

Make sure that the character is loaded first before running the repeat until loop, you can achieve this by using the CharacterAdded:Wait() function at top of your code.

When trying to set back the camera to normal or default, the CameraType property has to be Custom, and the CameraSubject property has to be the character’s Humanoid.

With that part I already have that in the 3rd line,

local Character = Player.Character or Player.CharacterAdded:Wait()