Current Camera Gets Stuck When Dying

Hello Developers, I have an issue, i am using a camera for a train and when someone sits on a seat it changes the camera and when leaving the seat the camera resets, but when i am sitting I resetted and the camera is stuck on its place i also used this script

Server

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		game:GetService("ReplicatedStorage").ResetCamera:FireClient(plr)
	end)
end)

Local

game:GetService("ReplicatedStorage").ResetCamera.OnClientEvent:Connect(function()
	print("FIRIRIEIEIDIDIDIID")

	CamSubject=nil
	LastCam=nil
	sitting=false

	Camera.CameraType = Enum.CameraType.Custom
	localplayer.CameraSubject=Character:WaitForChild("Humanoid")
	script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
end)
2 Likes
localplayer.CharacterAdded:Wait()

Add this code before you changing the camera subject to humanoid (in the Localscript)

1 Like

For Some Reason It Is Still Not Working But The Event Got Fired And the output from the print showed after localplayer.CharacterAdded:Wait()

(sorry for late responce) Can you show me the script?

no problem the script may be hard to understand but good luck

local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")

local sitting = false
local CamSubject = nil
local LastCam = nil
local UserInputService = game:GetService("UserInputService") 
local RunService = game:GetService("RunService") 

local plr= game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(plr.Name)
local Character = plr.Character

local localplayer = game:GetService("Players").LocalPlayer

local char = localplayer.Character
local hum:Humanoid = char:WaitForChild("Humanoid")

game:GetService("ReplicatedStorage").ResetCamera.OnClientEvent:Connect(function()
	localplayer.CharacterAdded:Wait()
	print("FIRIRIEIEIDIDIDIID")
	CamSubject=nil
	LastCam=nil
	sitting=false
	--NewCamera.Parent=game.Workspace
	Camera=Instance.new("Camera",game.Workspace)
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject=Character:WaitForChild("Humanoid")
	script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
end)


--[[game:GetService("ReplicatedStorage").ResetCamera.Event:Connect(function(id)
	if id==localplayer.UserId then
		localplayer.CharacterAdded:Wait()
		
		--localplayer.CameraType=Enum.CameraType.Custom
		--script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
		--localplayer.CameraSubject=Character:WaitForChild("Humanoid")
	end
	
end)--]]

game:GetService("ReplicatedStorage").Camera.OnClientEvent:Connect(function(Enabled:boolean, CameraSubject:Part, switch:boolean)
	print("Changing Camera")
	if switch==nil or not switch then
		if not Enabled then
			sitting=false
			CamSubject=nil

		else
			sitting=true
			CamSubject=CameraSubject
			LastCam=CamSubject
		end	
	elseif switch then
		if Enabled then
			sitting=true
		else
			sitting=false
		end
		if CameraSubject~=nil then
			LastCam=CameraSubject
		else
			CamSubject=LastCam
			LastCam=nil
		end	
	end
end)











game:GetService("ReplicatedStorage").CameraLocal.Event:Connect(function(switch:boolean)
	if switch then
		CamSubject=LastCam
	elseif not switch then
		CamSubject=nil
	end
end)


RunService.RenderStepped:Connect(function()
	if sitting and CamSubject~=nil then
		--Camera.CFrame=CamSubject.CFrame
		--Camera.CameraType=Enum.CameraType.Orbital
		script.Parent.Parent.CameraMode = Enum.CameraMode.LockFirstPerson
		Camera.CameraSubject=CamSubject
		--Camera.




	else
		Camera.CameraType=Enum.CameraType.Custom
		script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
		Camera.CameraSubject=nil
		Camera.CameraSubject=Character:WaitForChild("Humanoid")

	end
end)

game:GetService("ReplicatedStorage").ResetCamera.OnClientEvent:Connect(function()
	Character = localplayer.CharacterAdded:Wait()
	print("FIRIRIEIEIDIDIDIID")
	CamSubject=nil
	LastCam=nil
	sitting=false

	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject=Character:WaitForChild("Humanoid")
	script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
end)

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