Setting Camera's CFrame kills the client's player

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Fixing my camera script.
  2. What is the issue? Include screenshots / videos if possible!
    the Player dies on join.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking for solutions, none found.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CameraSubject = nil
game["Run Service"].RenderStepped:Connect(function()
	local Pos1 = game.Players.LocalPlayer.Character.HumanoidRootPart.Position--game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	local Pos2 = Vector3.new(0,0,0)
	
	workspace.CurrentCamera.CFrame = CFrame.new(Pos1,Pos2)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

If the player is being killed upon spawning, I don’t think that result has anything to do with the code you’ve posted. :confused:

2 Likes

This is the file. It never kills the player when the code is disabled, yet it does when its enabled.camera_test.rbxl (18.0 KB)

1 Like

Weird, my character has been dying when I play solo for an unrelated reason. It’s about 50/50 but it seems to have stopped. Maybe that’s why, because that code doesn’t look like something that would kill the player.

I’ll check it out.

The problem seems to be that you’re referencing the HumanoidRootPart before it exists. As the player getting killed, I have no idea, however, this code seems to work fine:

local LocalPlayer = game:GetService("Players").LocalPlayer -- LocalPlayer definition
local CurrentCamera = workspace.CurrentCamera

CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CameraSubject = nil

game:GetService("RunService").RenderStepped:Connect(function()
	if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then -- Check if the character and the HumanoidRootPart exist
		local Pos1 = game.Players.LocalPlayer.Character.HumanoidRootPart.Position--game.Players.LocalPlayer.Character.HumanoidRootPart.Position
		local Pos2 = Vector3.new(0,0,0)
		
		CurrentCamera.CFrame = CFrame.new(Pos1,Pos2)
	end
end)
1 Like

OK! Update using @detourious 's code, Ive figured out that when the player respawns after dying fromt he camera script, if you switch into server-side viewing, the player is still alive. You can then swap back, and then the player wont die.

EDIT: I still cant figure out why the player dies, maybe theres someway to simulate the player being AFK so that they arent stuck in a death loop? Im lost.

EDIT 2: Apparently, the player wont die at all if the game isnt focused. Maybe something with network owner?

ummmmm... ok. Scratch this whole thing. Apparenlty you dont die in official live servers, but you do in studio?! I guess.. problem solved? *(Maybe..?)*

EDIT: WRONG?!

Lets get some facts down:

  • When your character spawns in, its immediatley put into an infinite death loop.

  • The only out of said death loop, is to do one of the following:

    • Play in fullscreen
      OR
    • Dont focus the game.

… Why?

1 Like

This is happening because the Camera’s CFrame is being set as soon as the game starts, this leads to the character spawning under the world and then teleporting to the default spawn location, hence killing them.

As you’ve mentioned, it’s not going to be an issue with live games, but to fix it in studio, simply use the “Play Here” option or just simply add a spawn location.

2 Likes

How did you know this?! I thank you. I had no idea that setting camera cframes could kill the player. Thanks for the solution!

Actually this part is not accurate, I just made this assumption. If you noticed, when you start a studio test, you first see a blank game, then the loading screen is seen, then you see the baseplate.

At the point where you see nothing, this is where the character is teleported to, then teleported to the default spawn location.

Ohhh. Ok. Well, thanks for the help! If it werent for you (and everyone else here) I wouldnt be able to make my new (Probably not going to be popular) game. Its going to be similar to Beat Blast (If youve ever played it, if not go try it. Its a great game), and mixed with an MMORPG.