Camera stuck after changing character

The camera is stuck and is not being centered on the new character. I’m using server script

local zombie = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
local character = game.Workspace.Zombie
character.Name = zombie.Name
zombie.Character = character
2 Likes

Change the camera to track the new character, also only works in local scripts

How to do that?‍‍‍‍

local cam = workspace.CurrentCamera

cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = --the new character's HumanoidRootPart

More info watch this video

Or check out Roblox’s Documentation about Cameras

How can I do this with a server script?

Not possible, since each player has their own unique CurrentCamera, you have to do it within a local script

How can I check if the player is a zombie?

I fixed it now‍‍‍‍‍

while wait() do
	if game.Players.LocalPlayer:GetAttribute("Zombie") == true then
		local camera = game.Workspace.CurrentCamera
		camera.CameraType = Enum.CameraType.Custom
		camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	end
end

If you have a Team system then you can get what team the player is on, otherwise looking from your code, you can check if the character is a zombie by checking if the player’s name is, well, “Zombie”

You should probably use :GetAttributeChangedSignal() instead of a while loop.

local players = game:GetService("Players")

local player = players.LocalPlayer

local camera = workspace.CurrentCamera

local function zombieAttributeChanged()
    local char = player.Character
    if char then
        local hum = char:WaitForChild("Humanoid")
        camera.CameraType = Enum.CameraType.Custom
        camera.CameraSubject = hum
    end
end

player:GetAttributeChangedSignal("Zombie"):Connect(zombieAttributeChanged)
1 Like

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