How do you tie the camera back to the player?

local uis = game:GetService("UserInputService")

local zoom = 100
local fieldOfView = 9

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera

local isoCameraConnection

local function isometricCamera()
	if isoCameraConnection then isoCameraConnection:Disconnect() end
	isoCameraConnection = runServ.RenderStepped:Connect(function()
		camera.CameraType = Enum.CameraType.Scriptable
		camera.FieldOfView = fieldOfView

		if player.Character and player.Character:FindFirstChild("Head") then
			game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
			camera.CFrame = CFrame.new(Vector3.new(character.Head.Position.X + zoom, character.Head.Position.Y + zoom, character.Head.Position.Z + zoom), character.Head.Position)
		end
	end)
end

local function basicCamera()
	--if isoCameraConnection then
	--	isoCameraConnection:Disconnect()
	--	isoCameraConnection = nil
	--end
	--camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = character.Humanoid
	print(character.Humanod)
end

uis.InputBegan:Connect(function(input, chatting) 
	if chatting then return end -- if player is typing in chat this function will not run

	if input.KeyCode == Enum.KeyCode.F then
		isometricCamera()
	elseif input.KeyCode == Enum.KeyCode.R then
		basicCamera()
	end
end)

I’m trying to make isometric camera back to normal camera but I don’t know how to do it, help please

change the CameraType back to Custom

edit: you probably commented that out for a reason?

1 Like

--camera.CameraType = Enum.CameraType.Custom

Remove the 2 dashes from this line to get your CameraType set back to Custom.

1 Like
local function basicCamera()
	--if isoCameraConnection then
	--	isoCameraConnection:Disconnect()
	--	isoCameraConnection = nil
	--	camera.CameraSubject = character:WaitForChild("Humanoid")
	--	print(character:WaitForChild("Humanoid"))
	--end
	camera.CameraSubject = character:WaitForChild("Humanoid")
	camera.CameraType = Enum.CameraType.Custom
	
end

like this?

Your issue might be related to this post. Take a look:

Tldr;

disconnecting events no longer happen instantly. You’ll need to add a debounce within your renderstepped connection.

Can you show me exactly how I need to do this if you don’t mind)

I stated exactly how to do it in my first post. Remove the 2 – at the beginning of that line.

In addition to what I wrote, it appears you don’t disconnect isoCameraConnection at all… so .CameraType will keep getting overriden.

local function basicCamera()
	--if isoCameraConnection then
	--	isoCameraConnection:Disconnect()
	--	isoCameraConnection = nil
	--end
	camera.CameraType = Enum.CameraType.Custom
	--camera.CameraSubject = character.Humanoid
	--print(character.Humanod)
end

maybe like this?

Just wanted to clarify that we do disconnect events immediately when you call the disconnect method. It’s only in the case of destroying the object that we defer the disconnections (to ensure you get all of the events).

1 Like

That’s exactly what I said.
Try it, see if it works.

I checked and it didn’t fix the error, alas.

Try this


local uis = game:GetService("UserInputService")

local zoom = 100
local fieldOfView = 9

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local runServ = game:GetService("RunService")
local camera = workspace.CurrentCamera

local isoCameraConnection

local function isometricCamera()
	if isoCameraConnection then isoCameraConnection:Disconnect() end
	isoCameraConnection = runServ.RenderStepped:Connect(function()
		camera.CameraType = Enum.CameraType.Scriptable
		camera.FieldOfView = fieldOfView

		if player.Character and player.Character:FindFirstChild("Head") then
			game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
			camera.CFrame = CFrame.new(Vector3.new(character.Head.Position.X + zoom, character.Head.Position.Y + zoom, character.Head.Position.Z + zoom), character.Head.Position)
		end
	end)
end

local function basicCamera()
	if isoCameraConnection then
	isoCameraConnection:Disconnect()
	isoCameraConnection = nil
	end
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = character:FindFirstChild(“Humanoid”)
        camera.FieldOfView = 90 -- standard
	print(character:FindFirstChild(“Humanoid”))
end

uis.InputBegan:Connect(function(input, chatting) 
	if chatting then return end -- if player is typing in chat this function will not run

	if input.KeyCode == Enum.KeyCode.F then
		isometricCamera()
	elseif input.KeyCode == Enum.KeyCode.R then
		basicCamera()
	end
end)

Not able to test this since I’m on phone, lmk if it works or not :smile:

2 Likes

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