I have this connected event function I need to disconnect:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Camera1 = ReplicatedStorage:WaitForChild("Camera1") local Camera = game:GetService("Workspace").CurrentCamera local Camera1Object = game:GetService("Workspace"):WaitForChild("Cam1"):WaitForChild("Cam") --Ignore why this looks weird --This function needs to disconnect after I'm done using it Camera1.OnClientEvent:Connect(function() Camera.CameraType = Enum.CameraType.Scriptable Camera1Object:GetPropertyChangedSignal("CFrame"):Connect(function() Camera.CFrame = Camera1Object.CFrame * CFrame.Angles(0,67.5,0) * CFrame.new(0,0,-1) --Also ignore why this looks so weird end) end)
There's likely a simple solution I'm overlooking. The reason I need to disconnect this is because after the player has finished looking at the camera I need to return the player's camera to its original CFrame, but this connected function is still firing therefor I need to disconnect it.
I fixed it:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Camera1 = ReplicatedStorage:WaitForChild("Camera1") local Camera = game:GetService("Workspace").CurrentCamera local Camera1Object = game:GetService("Workspace"):WaitForChild("Cam1"):WaitForChild("Cam") local CameraNormal = ReplicatedStorage:WaitForChild("CameraNormal") local Connection Camera1.OnClientEvent:Connect(function() Camera.CameraType = Enum.CameraType.Scriptable local function CFrameProperty() Camera.CFrame = Camera1Object.CFrame * CFrame.Angles(0,67.5,0) * CFrame.new(0,0,-1) end local Connection = Camera1Object:GetPropertyChangedSignal("CFrame"):Connect(CFrameProperty) CameraNormal.OnClientEvent:Connect(function() Camera.CameraType = Enum.CameraType.Custom Connection:Disconnect() end) end)