Basically, I have this system here to change players’ characters upon request. I am pretty certain that the game automatically changes the player’s CameraSubject to the new character. The problem here is that I don’t want the camera CFrame (basically everything about the position, rotation, etc.) to change.
Is there a way to do this?
What I’ve tried:
function AssetsLoader:LoadPlayerCharacter(player, characterToLoadName)
if game:GetService("RunService"):IsClient() then
return
end
if not player.Character then
player:LoadCharacter()
end
if player.Character then
local characterToLoad = game:GetService("ServerStorage").CharactersStorage:FindFirstChild(characterToLoadName)
if characterToLoad then
CameraRequest:InvokeClient(player)
local newcharacterToLoad = characterToLoad:Clone()
newcharacterToLoad.Name = player.Name
newcharacterToLoad.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
player.Character = newcharacterToLoad
newcharacterToLoad.Parent = game.Workspace
end
end
end
LocalScript:
CameraRequest.OnClientInvoke = function()
local CurrentCamera = game.Workspace.CurrentCamera
local oldCameraCFrame = CurrentCamera.CFrame
local cameraCFrameChangeConnection
cameraCFrameChangeConnection = LocalPlayer.Character:GetPropertyChangedSignal("Parent"):Connect(function()
CurrentCamera.CFrame = oldCameraCFrame
cameraCFrameChangeConnection:Disconnect()
end)
end
As you can see, I have tried to change the camera CFrame to the old one with two different events (the old character being removed and the CameraSubject being changed). But it ran too fast causing it to not work at all (I know that I can simply put task.wait(sec) but I want to know if there’s a better way).
Guessing your camera type is already Scriptable, change it to Fixed, this will fixate the camera in one position, where you last left off when changing the type of the camera.
Change the type to Fixed then Change it to custom (will automaticlly set CFrame and Everything by default if you have set your cameraSubject to the new Humanoid), If you are using Scriptable camera Type then this will be the same as how you’ve handled the old event. OverAll Just make sure to set the camera subject to the new character’s Humanoid.
Just for reference, here is what I am trying to do:
I want to set the camera’s behaviour to not change at all (mainly the rotation). From the vid you can see there’s a bit of delay before it changes due to me using task.wait(0.1), but is there a way to completely prevent the camera CFrame change?
But as I’ve guessed it still doesn’t work as it still changes the rotation with respect to the new character humanoid. What I am trying to do here is to prevent that rotation from happening (or you can say I want the camera to stay like how it was BEFORE the character change.
Make it scriptable, Get the orientation or CFrame of the camera when the type is Fixed before changing it to scriptable and when when you change it to scriptable just simply set the cframe of the camera to the fixed cframe.
That’s what I have been trying to do. But it doesn’t work properly due to how it immediately changes the CFrame to the CameraSubject hence why I said earlier if I did a task.wait() there, it’ll work but with a delay.
Also I’m not setting it to Scriptable as I want it to follow the new player’s character afterward so it’s the Custom (default) one.
CameraRequest.OnClientInvoke = function()
local CurrentCamera = game.Workspace.CurrentCamera
local oldCameraCFrame = CurrentCamera.CFrame
local cameraCFrameChangeConnection
cameraCFrameChangeConnection = LocalPlayer.Character:GetPropertyChangedSignal("Parent"):Connect(function()
local RenderStepped
RenderStepped = RunService.RenderStepped:Connect(function()
CurrentCamera.CFrame = oldCameraCFrame
cameraCFrameChangeConnection:Disconnect()
if CurrentCamera.CFrame == oldCameraCFrame then
RenderStepped:Disconnect()
end
end)
end)
end