Help on how CameraTypess

CameraHandler - Cloned to PlayerGui whenever player dies

-- Global Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

-- Object Referencing
local cameraFolder = game.Workspace:WaitForChild("Cameras")
local starterCamera = cameraFolder:WaitForChild("StarterCamera")
local attackerCamera = cameraFolder:WaitForChild("AttackerCamera")
local defenderCamera = cameraFolder:WaitForChild("DefenderCamera")
local cameraEvent = ReplicatedStorage:FindFirstChild("CameraEvent")

local player = game.Players.LocalPlayer

-- Value Referencing
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local gameValues = ReplicatedStorage:FindFirstChild("GameValues")

-- Value Objects
local gameStatus = gameValues:FindFirstChild("GameStatus") 
local camera = game.Workspace.CurrentCamera

--[[ Camera Event Types
	PreGame
	Died
	GameEnded
	
	Reset
]]

local function setScriptable()
	repeat
		camera.CameraType = Enum.CameraType.Scriptable
		task.wait(0.1)
	until camera.CameraType == Enum.CameraType.Scriptable
end

cameraEvent.OnClientEvent:Connect(function(cameraType)
	if cameraType == "PreGame" then
		setScriptable()
		camera.CFrame = starterCamera.CFrame
	else if cameraType == "GameEnded" or cameraType == "Died" then
			if player.Team == Teams.Defender then
				setScriptable()
				camera.CFrame = defenderCamera.CFrame
			else if player.Team == Teams.Attacker then
					setScriptable()
					camera.CFrame = attackerCamera.CFrame
				end
			end
			else if cameraType == "Reset" then
				repeat
					camera.CameraType = Enum.CameraType.Custom
					task.wait(0.1)
				until camera.CameraType == Enum.CameraType.Custom
			end
		end
	end
end)

GameLogic

-- Player Respawn
ReplicatedStorage:WaitForChild("DeathEvent").OnServerEvent:Connect(function(player)
	if canSpawn.Value == true and gameStatus.Value == "GameRunning" then
		script.ScreenGui:Clone().Parent = player.PlayerGui
		cameraEvent:FireClient(player, "Died")
		task.wait(3)	
		if gameStatus.Value == "GameRunning" then
			cameraEvent:FireClient(player, "Reset")
			player:LoadCharacter()
		end
	end
end)

Players.PlayerAdded:Connect(function(player)
	gameStatus.Value = ""
	print(player.Name.." has joined.")
	script.ScreenGui:Clone().Parent = player.PlayerGui
	cameraEvent:FireClient(player, "PreGame")
	print("Done")
end)

Problem: When the player dies, it’s camera CFrame is set to a part, after 3 seconds, they respawn, I have to call cameraEvent:FireClient(player, "Reset") before player:LoadCharacter() or else, if I call it after the player’s character is loaded, then the player’s camera CFrame is not changed while the character is loaded. Does anyone have any ideas or know how to make it so that you don’t have to see your character for half a second before respawning for the camera manipulation to work well? I am not very good at camera manipulation or experienced :frowning:

robloxapp-20230924-1820054.wmv (1.7 MB)

This likely happen because when you load character any GUI that are not in StarterGui and Have property ResetOnSpawn enabled then they will be deleted you can try disabled ResetOnSpawn on GUI

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