Loadcharacter with camera stay keeping

  1. What do you want to achieve? Keep it simple and clear!
    I wanted to make LoadCharacter that keep your camera position
  2. What is the issue? Include screenshots / videos if possible!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have no idea for that. I tried making the Camera becomes Scriptable.

local loadCharEvent = game.ReplicatedStorage.loadCharacter

loadCharEvent.OnServerEvent:Connect(function(player)

	local currentCharacter = player.Character
	local currentPosition

	if currentCharacter then
		local humanoidRootPart = currentCharacter:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			currentPosition = humanoidRootPart.Position
		end
	end


	player:LoadCharacter()


	if currentPosition then
		local newCharacter = player.Character
		if newCharacter then
			local newHumanoidRootPart = newCharacter:FindFirstChild("HumanoidRootPart")
			if newHumanoidRootPart then
				newHumanoidRootPart.CFrame = CFrame.new(currentPosition)
			end
		end
	end
end)

2 Likes

you can pass the player’s camera cframe to the server through a remotefunction

1 Like

I think there is something wrong that im not expected


ServerScript

local loadCharEvent = game.ReplicatedStorage.loadCharacter
local getCameraCFrame = game.ReplicatedStorage.SendCameraCFrame

loadCharEvent.OnServerEvent:Connect(function(player)
	local currentPosition
	local currentCharacter = player.Character

	if currentCharacter then
		local humanoidRootPart = currentCharacter:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			currentPosition = humanoidRootPart.Position
		end
	end


	local cameraCFrame = getCameraCFrame:InvokeClient(player)

	player:LoadCharacter()

	if currentPosition then
		local newCharacter = player.Character
		if newCharacter then
			local newHumanoidRootPart = newCharacter:FindFirstChild("HumanoidRootPart")
			if newHumanoidRootPart then
				newHumanoidRootPart.CFrame = CFrame.new(currentPosition)
			end
		end
	end


	game.Workspace.CurrentCamera.CFrame = cameraCFrame
end)

Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getCameraCFrame = ReplicatedStorage.SendCameraCFrame

getCameraCFrame.OnClientInvoke = function()
	return game.Workspace.CurrentCamera.CFrame
end

1 Like

I think the problem is that you set the camera’s CFrame in the server script. You have to set it through a client script, I think you just forgot.

1 Like

Try using a RemoteEvent to send the camera’s CFrame to the client.
Keep in mind, relayCameraCFrame (RelayCameraCFrame) would be a RemoteEvent placed in ReplicatedStorage.

Server Script

local loadCharEvent = game.ReplicatedStorage.loadCharacter
local getCameraCFrame = game.ReplicatedStorage.SendCameraCFrame
local relayCameraCFrame = game.ReplicatedStorage.RelayCameraCFrame

loadCharEvent.OnServerEvent:Connect(function(player)
	local currentPosition
	local currentCharacter = player.Character

	if currentCharacter then
		local humanoidRootPart = currentCharacter:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			currentPosition = humanoidRootPart.Position
		end
	end


	local cameraCFrame = getCameraCFrame:InvokeClient(player)

	player:LoadCharacter()

	if currentPosition then
		local newCharacter = player.Character
		if newCharacter then
			local newHumanoidRootPart = newCharacter:FindFirstChild("HumanoidRootPart")
			if newHumanoidRootPart then
				newHumanoidRootPart.CFrame = CFrame.new(currentPosition)
			end
		end
	end


	relayCameraCFrame:FireClient(player, cameraCFrame)
end)

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getCameraCFrame = ReplicatedStorage.SendCameraCFrame
local relayCameraCFrame = ReplicatedStorage.RelayCameraCFrame

getCameraCFrame.OnClientInvoke = function()
	return game.Workspace.CurrentCamera.CFrame
end

relayCameraCFrame.OnClientEvent:Connect(function(frame)
    workspace.CurrentCamera.CFrame = frame
end)

I’ve tried printing the frame position.
But when I loadcharcter, it only change the camera to -23.091, 7.735, -18.827 that is behind of players’s back. I think the script works but there is anything prevent player from it?