(STUDIO BUG?) Plugin, spawn function not working after update

I need help, the main function of my plugin suddenly stopped working, probably due to some update.

It is a function in the plugin that simply spawns a model in front of the user’s camera. The model has a primarypart.

The problem: the model spawns at a specific location (near the center of the world) for some reason, and even stranger, restarting the studio occasionally resolves it.
This problem started appearing 20 days ago, the plugin with this code has been working for 2 years with no problem.

Spawn function in my plugin:

local ChangeHistoryService = game:GetService("ChangeHistoryService")
local camera = workspace.CurrentCamera

local function spawnfunction()
	local model = script.Parent.Other.SPZ --model to spawn
	local clone = model:Clone()
	local Location = camera.CFrame.Position + (camera.CFrame.LookVector * 5)
	clone.Parent = workspace
	local x, y, z = workspace.CurrentCamera.CFrame:ToEulerAnglesYXZ()
	local lookValue 
	if y > -0.78539818525314333 and y < 0.7853981852531433 then
		lookValue = 0
	elseif y > 0.7853981852531433 and y < 2.356194496154785  then
		lookValue = 90
	elseif y > -2.356194496154786 and y < -0.78539818525314332 then
		lookValue = -90
	else
		lookValue = 180
	end
	clone:SetPrimaryPartCFrame(CFrame.new(Location)*CFrame.Angles(0,math.rad(lookValue),0))
	ChangeHistoryService:SetWaypoint("yo")
end

output shows no error
(I underline this problem for some reason happens sometimes! )

Have you always used :ToEulerAnglesYXZ() instead of :ToEulerAnglesXYZ()?

yes always and even if I change it to XYZ it does the same thing

I already know why it is (probably) check out this video 1 and 4 attempts it does the problem and 2, 3 it works, the big difference between those attempts is that the attempts that don’t work have a new loading system! (I have verified this several times outside the video!)

To add to this new update, when I end testing my studio freezes for a few seconds?? The particles are still moving but I cannot move my camera or interact with studio since the recent version

:SetPrimaryPartCFrame is deprecated, so that might be the issue. Try using :PivotTo instead.

I tried it, unfortunately it has the exact same problem, only the studio thinks the camera is in the center of the map for some reason. I repeat it only happens when it loads using the new loading window.

So, when you print camera.CFrame.Position, does it return 0, 0, 0?

Good idea what I found out

  1. when I print the cframe to the command line everything works
    I put the print function in the plugin’s spawn function
  2. 0, 20, 20 - at this position it says it is my camera which is nonsense
  3. when I updated the plugin suddenly the camera shows the correct camera values

Is it working now, or is it just printing out the correct values?

No it doesn’t work, after the plugin update (which is like reinstalling the plugin) the camera starts working but as soon as I restart the studio/place the problem is back, I meant to imply that the problem is when the place is first loaded

Consider trying different methods for rotating and positioning the model

	local location = CFrame.new(cam.CFrame.Position + (cam.CFrame.LookVector * 5), cam.CFrame.Position)
	local x, y, z = location:ToOrientation()
	
	clone:PivotTo(CFrame.new(location.Position) * CFrame.Angles(0, math.rad(roundToNearest90(math.deg(y))), 0))

roundToNearest90 function:

local function roundToNearest90(val)
	local signValue = math.sign(val)
	return math.floor(math.abs((val + (45 * signValue)) / 90)) * (90 * signValue)
end