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?