Why does camera manipulation only work if I do it slowly?

Whenever you equip a tool, I want the camera to move to a specific part and freeze the camera so you can’t move it. Then if you unequip the tool I want the camera to return back. Here is the script I used:

local tool = script.Parent
local cameras = game.Workspace.Cameras
local player = game:GetService("Players").LocalPlayer
local cframe = nil

tool.Equipped:Connect(function()
	cframe = game.Workspace.CurrentCamera.CFrame
	game.Workspace.CurrentCamera.CameraSubject = cameras.Cam12
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
	game.Workspace.CurrentCamera.CFrame = cameras.Cam12.CFrame
end)

tool.Unequipped:Connect(function()
	local character = player.Character or player.CharacterAdded:Wait()
	game.Workspace.CurrentCamera.CameraSubject = character.Humanoid
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.Workspace.CurrentCamera.CFrame = cframe
end)

That script didn’t really work, it was buggy. But it worked when I added a wait(1) in between each line of code when I equip the tool:

local tool = script.Parent
local cameras = game.Workspace.Cameras
local player = game:GetService("Players").LocalPlayer
local cframe = nil

tool.Equipped:Connect(function()
	cframe = game.Workspace.CurrentCamera.CFrame
	game.Workspace.CurrentCamera.CameraSubject = cameras.Cam12
    wait(1)
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
    wait(1)
	game.Workspace.CurrentCamera.CFrame = cameras.Cam12.CFrame
end)

tool.Unequipped:Connect(function()
	local character = player.Character or player.CharacterAdded:Wait()
	game.Workspace.CurrentCamera.CameraSubject = character.Humanoid
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.Workspace.CurrentCamera.CFrame = cframe
end)

But obviously I don’t want it to take that long, so how can I do this?

2 Likes

Maybe you could do game.Workspace:WaitForChild("CurrentCamera")

Try putting a print before these lines and tell me if they print

that just sends an infinite yield

It works fine when I unequip the tool. Just not when I equip it. I put a print before the first one though and it printed obviously. Not sure how that would help though.

Update: I got it working by putting a task.wait()

local tool = script.Parent
local cameras = game.Workspace.Cameras
local player = game:GetService("Players").LocalPlayer
local cframe = nil

tool.Equipped:Connect(function()
	cframe = game.Workspace.CurrentCamera.CFrame
	game.Workspace.CurrentCamera.CameraSubject = cameras.Cam12
	task.wait()
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
	task.wait()
	game.Workspace.CurrentCamera.CFrame = cameras.Cam12.CFrame
end)

tool.Unequipped:Connect(function()
	local character = player.Character or player.CharacterAdded:Wait()
	game.Workspace.CurrentCamera.CameraSubject = character.Humanoid
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.Workspace.CurrentCamera.CFrame = cframe
end)

thanks for help though.