Player's CurrentCamera sometimes stuck to last death cframe

What I want to achieve?
My end goal is that I want all players to have a normal working FPS camera when they spawn into the game from the game-menu.

I want to find a way to force reset the players camera back to the living player character, however currently for some reason the player’s camera is not updating correctly and getting stuck to their previous death position.

What is the issue?
The issue is when players die and respawn sometimes they have a chance to break their currentCamera, so when they try to spawn into the game again from the menuscreen, the camera is positioned on their last death head/humanoidroot cframe position for some reason?

What solutions have I tried so far?
I have tried running loops or not using loops nothing seems to fix it, I need help creating a script that forces a camera reset probably.

Below is a localscript inside of a gui in startergui, startergui has resetonspawn set to true. The menu system works perfectly except occasionally camera breaks when giving the player’s camera back randomly without rhyme or reason.


local RunService = game:GetService("RunService") --arjun9022 was here, using runservice is more efficient than wait()
local StarterGui = game:GetService("StarterGui")

local Player = game.Players.LocalPlayer
local PlayerUI = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local NewsBanner = script.Parent:WaitForChild("ImageLabel")

local PlayButton = script.Parent.ImageLabel.PlayButton
local GearButton = script.Parent.ImageLabel.GearButton
local StatsButton = script.Parent.ImageLabel.StatsButton
local StoreButton = script.Parent.ImageLabel.StoreButton
local HelpButton = script.Parent.ImageLabel.HelpButton

local everything = script.Parent.Parent.MainMenuGUI

local Backdrops = script.Parent.ImageLabel.BackDrops
local PlayFrame = Backdrops.PlayFrame
local GearFrame = Backdrops.GearFrame
local StatsFrame = Backdrops.StatsFrame 
local StoreFrame = Backdrops.StoreFrame
local HelpFrame = Backdrops.HelpFrame
local DeployButton = PlayFrame.DeployButton

repeat wait()  -- using runservice because i thought the game was loading too fast for the player idk
	RunService.Stepped:wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

Camera.CFrame = workspace.CameraPart.CFrame
Camera.FieldOfView = 18
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
script.Parent.ImageLabel.MenuMusic.Playing = true


DeployButton.MouseButton1Click:Connect(function()
	Camera.CameraType = Enum.CameraType.Custom
	Camera.FieldOfView = 70

	
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

	
	PlayerUI:WaitForChild("StatusUI").Enabled = true
	PlayerUI.StatusUI.Compass.Enabled = true
	script.Parent.ImageLabel.MenuMusic.Playing = false
	script.Parent.ImageLabel.Visible = false
	everything:Destroy()
end)

The menu system in my game uses the cframe coordinates of a camera brick as soon as they launched the game, once the player click DEPLOY in the menu it returns their camera to their player FPS mode, but for some reason occasionally the camera is stuck to where they last died. the menu works flawlessly, and the camera angle is perfect, I only run into this issue when players deploy to play the game after dying a few times.

The CameraPart is located in workspace, players spawn into the map and load in but their camera position is changed to the camerapart while in the menu. When players hit the deploy button their camera is returned to their player, but this fails sometimes.

I would like help forcing camera resets on spawn, or running some sort of checks to make sure the camera is always fixed when respawning and hitting deploy.

Or can someone offer a better method of using a menu system that involves not automatically loading the character and scripting a manual character load, so this glitch can’t happen in the first place?

Thank you.

3 Likes

You may have tried this, but if you haven’t try repositioning the camera in your repeat loop:

repeat
	RunService.RenderStepped:wait() -- RenderStepped happens before a frame is rendered on the client so it's good to use when working with cameras
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = workspace.CameraPart.CFrame
until Camera.CameraType == Enum.CameraType.Scriptable and Camera.CFrame == workspace.CameraPart.CFrame
2 Likes