im making morph system, i want to prevent the camera from resetting, i try using the “lastCframe” system where i took the camera cframe before it morph, but my script doesnt work. what am i doing wrong?
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local MorphRemoteEvent = ReplicatedStorage:WaitForChild("Event"):WaitForChild("MorphRemoteEvent")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local camera = game:GetService("Workspace").CurrentCamera
local lastCamPos
local lastCamRotation
mouse.Button1Down:Connect(function()
local target = mouse.Target
lastCamPos = camera.CFrame.Position
lastCamRotation = camera.CFrame.LookVector
if target and CollectionService:HasTag(target, "Morphable") then
MorphRemoteEvent:FireServer(target)
end
end)
MorphRemoteEvent.OnClientEvent:Connect(function(morphedCharacterName)
local morphedCharacter = workspace:WaitForChild(morphedCharacterName)
camera.CameraSubject = morphedCharacter:WaitForChild("Humanoid")
local targetPosition = morphedCharacter:WaitForChild("HumanoidRootPart").Position
local newCFrame = CFrame.new(lastCamPos, targetPosition) * CFrame.new(0, 0, -10)
camera.CFrame = newCFrame
end)