Camera not returning to it's OriginalCam Position

local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local camPart = workspace.campart

local Scale = 5000

cam.CameraType = Enum.CameraType.Scriptable

game:GetService("RunService").RenderStepped:Connect(function()
	local center = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
	local x = mouse.X - center.X / 2
	local y = mouse.Y - center.Y / 2
	local xOffset = x/Scale 
	local yOffset = y/Scale

	local lookAtPoint = camPart.Position+camPart.CFrame.LookVector*5
	local vector = Vector3.new(
		lookAtPoint.X - xOffset,
		lookAtPoint.Y - yOffset,
		lookAtPoint.Z - xOffset)  

	local result = CFrame.lookAt(camPart.CFrame.Position,vector)

	cam.CFrame = result
end)

script.Parent.LoadGame.MouseButton1Click:Connect(function()
	cam.CameraType = Enum.CameraType.Custom
	print("OrigCam")
end)

There are no Errors and the print also worked, don’t know why. Please help me.

What’s, the original carma position?

1 Like

The player is the original camera position

where is is the script? Is it in serverscriptservice?

The local script is in StarterGui in a ScreenGui

Maybe put it in starterplayer>staterplayerscipts

Isn’t the RunService still running when player activated LoadGame?

if so then how do I stop the that?

I dont know if thats the only issue, but you could do it like this:

local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local camPart = workspace.campart

local Scale = 5000

cam.CameraType = Enum.CameraType.Scriptable

-- keep the connection into a variable
local RSrun = game:GetService("RunService").RenderStepped:Connect(function()
	local center = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
	local x = mouse.X - center.X / 2
	local y = mouse.Y - center.Y / 2
	local xOffset = x/Scale 
	local yOffset = y/Scale

	local lookAtPoint = camPart.Position+camPart.CFrame.LookVector*5
	local vector = Vector3.new(
		lookAtPoint.X - xOffset,
		lookAtPoint.Y - yOffset,
		lookAtPoint.Z - xOffset)  

	local result = CFrame.lookAt(camPart.CFrame.Position,vector)

	cam.CFrame = result
end)

script.Parent.LoadGame.MouseButton1Click:Connect(function()
	RSrun:Disconnect() -- disconnect it when needed
	cam.CameraType = Enum.CameraType.Custom
	print("OrigCam")
end)

Thanks, it work. I looked more about it, and looks like it fixed the problem

I think this makes it more shorter

local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local camPart = workspace.campart

local Scale = 5000

cam.CameraType = Enum.CameraType.Scriptable

fart = game:GetService("RunService").RenderStepped:Connect(function()
	local center = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
	local x = mouse.X - center.X / 2
	local y = mouse.Y - center.Y / 2
	local xOffset = x/Scale 
	local yOffset = y/Scale

	local lookAtPoint = camPart.Position+camPart.CFrame.LookVector*5
	local vector = Vector3.new(
		lookAtPoint.X - xOffset,
		lookAtPoint.Y - yOffset,
		lookAtPoint.Z - xOffset)  

	local result = CFrame.lookAt(camPart.CFrame.Position,vector)

	cam.CFrame = result
end)

script.Parent.LoadGame.MouseButton1Click:Connect(function()
	cam.CameraType = Enum.CameraType.Custom
	fart:Disconnect()
	print("Set to OrigCam")
end)
1 Like

:crazy_face: maybe the “fart” variable should be disconnected before setting the CameraType.Custom. Idk, just to avoid possible glitches :v

1 Like

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