Changing the player's character breaks the camera?

i’m trying to make a game, and i’ve got the meat and potatoes of the logic done, but when i try to change the player’s character, it breaks their camera? i have no idea why this happens, nor any idea of how to fix it. any help is appreciated!

footage of the issue that i’m having:

the problematic script, specifically the part where it says: shark_player.Character = new_shark

-- services and all that jazz
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

-- config
local round_started = false
local round_duration = 150
local finished_duration = 4 -- how long to wait after the round finishes
local intermission_duration = 20
local min_players = 0

-- everything else
local shark_team = Teams:WaitForChild("blahaj")
local civilian_team = Teams:WaitForChild("civilian")
local spectator_team = Teams:WaitForChild("spectator")

local asset_folder = ReplicatedStorage.assets
local shark_model = asset_folder.plr_shark
local shark_player = nil -- keep track of the current shark

local function setup(player, team)
	player.Team = team
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	
	if humanoid then
		humanoid.Died:Connect(function()
			player.Team = spectator_team
			if player == shark_player and round_started then
				end_round()
			end
		end)
	end
end

-- main round-handling logic
local function start_round()
	round_started = true
	print(`round started`)

	local players = Players:GetPlayers()
	if #players < min_players then
		print(`not enough players needed to start the game`)
		round_started = false
		return 
	end

	local shark_index = math.random(1, #players)
	shark_player = players[shark_index]

	-- setup shark and civilians
	setup(shark_player, shark_team)
	local new_shark = shark_model:Clone()
	new_shark.Parent = workspace
	shark_player.Character = new_shark

	for _, player in ipairs(players) do
		if player ~= shark_player then
			setup(player, civilian_team)
		end
	end

	-- main countdown
	for i = round_duration, 1, -1 do
		if not round_started then
			break
		end
		task.wait(1)
		print(`{i} seconds left`)
	end

	if round_started then
		task.wait(finished_duration)
	end

	end_round()
end

function end_round()
	if not round_started then return end -- prevent multiple calls
	round_started = false
	print(`round ended`)
	for _, player in ipairs(Players:GetPlayers()) do
		player.Team = spectator_team
	end
end

while true do
	task.wait(intermission_duration)
	print(`intermission done...`)
	start_round()
end

This is likely because the CameraSubject is still your old character. Try updating workspace.CurrentCamera.CameraSubject = NewCharacter.Humanoid (assuming NewCharacter has a Humanoid; if it doesn’t, use NewCharacter.PrimaryPart)

1 Like

Keep in mind that currentcamera is a client only object! so you have to call it from a local script

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