Want to make an illusion of fake exit using viewport

Before you say “Just use a transparent block” or something, let me explain what exactly I want.
I have a market that you can physically enter. If you go too far into the building, you touch a transparent block and teleport to a building that looks similar to the one you were just in, except it goes on forever and ever. There is an exit that is supposed to give it the illusion of a fake exit with a viewport. However, even with my script, the viewport camera is stuck facing forward.
Screen Shot 2022-09-22 at 6.50.10 PM
This illusion looks so unreal
I would also like a more efficient method in doing this as I have limited scripting experience (I have tried remote events)
Script:

local cam = game.Workspace.Camera
local camcframe
camcframe = cam.CFrame
local x, y, z = camcframe:ToEulerAnglesXYZ()
local debounce = false
local repstor = game:GetService("ReplicatedStorage")
local xval = repstor:WaitForChild("XCam")
local yval = repstor:WaitForChild("YCam")
local zval = repstor:WaitForChild("ZCam")
while true do
	if debounce == false then
		debounce = true
		x, y, z = camcframe:ToEulerAnglesXYZ()
		xval = repstor:WaitForChild("XCam")
		yval = repstor:WaitForChild("YCam")
		zval = repstor:WaitForChild("ZCam")
		xval.Value = x
		yval.Value = y
		zval.Value = z
			task.wait(0.05)
			debounce = false
	else
		return
	end
end

Local Script that (is supposed to) rotate the viewport cam:

local repstor = game:GetService("ReplicatedStorage")
local xval = repstor:WaitForChild("XCam")
local yval = repstor:WaitForChild("YCam")
local zval = repstor:WaitForChild("ZCam")
local cam = script.Parent
local dbounce = false
while true do
	if dbounce == false then
		dbounce = true
		cam.CFrame = CFrame.Angles(xval, yval, zval)
		task.wait(0.01)
		dbounce = false
	end
end

Thanks for the help!

(If you reply to this after an hour, please expect a late reply. It is late at night at the time I am posting this and I have classes. Sorry for the inconvenience)

the current camera of the server is different from the camera of the player, thats why nothing is moving

1 Like

Oh yeah, I remember now. :sweat_smile: I forgot a lot of things after my break. I’ll redo my code and message you asap if anything happens. Thanks for replying :slight_smile:
PS: Isn’t the camera of the player accessed by Workspace.CurrentCamera? I can’t find anything else related to what I’m looking for

Nothing happened, disabled the script and changed local script to

local plrcam = game.Workspace.CurrentCamera
x, y, z = plrcam:ToEulerAnglesXYZ()
local cam = script.Parent
local dbounce = false
while true do
	if dbounce == false then
		dbounce = true
		cam.CFrame = CFrame.Angles(x, y, z)
		task.wait(0.01)
		dbounce = false
	end
end

What am I doing wrong?

debug print if x, y, and z are changing

also CFrame.Angles takes math.rad() values

I tried printing and nothing happened at all



Don’t mind that random Hello world, it is an irrelevant script
I noticed that while defining x, y, and z I was not using local (Don’t know if it’s even important in this case) and tried adding it, nothing happened yet again
After I took the pics I changed

cam.CFrame = CFrame.Angles(x, y, z)

to

cam.CFrame = CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))

Although that didn’t change the output

Going off for the night, I’ll check the replies tomorrow

you sure the script is running? try moving it out of the veiwport camera

Sorry for the late reply, I went to bed early. I’ll try this as soon as Roblox Studio gets better and I can use it

Ok the script ran after I put it directly under the viewport frame (Not sure why)
But then I get the error:

Players.SimplySquidtastic.PlayerGui.Viewport.ViewportFrame.LocalScript:10: attempt to index nil with 'CFrame'  -  Client - LocalScript:10

Code:

print("Script is running")
local plrcam = game.Workspace.CurrentCamera
local x, y, z = plrcam.CFrame:ToEulerAnglesXYZ()
local cam = script.Parent:FindFirstChild("ViewportCam")
local dbounce = false
while true do
	if dbounce == false then
		dbounce = true
		print(x, y, z)
		cam.CFrame = CFrame.Angles(math.rad(x), math.rad(y), math.rad(z)) --Line 10
		task.wait(0.01)
		dbounce = false
	end
end

Using WaitForChild instead of FindFirstChild gives me an infinite yield possible error.

The error is saying there is no “ViewportCam” inside the viewport frame. The code is running because local scripts only work under specific parents:
image

Ahh, ok, I understand now, but why isn’t my code working now? To my knowledge it should print x y and z, and FindFirstChild/WaitForChild won’t work on line 4

So far I have not found a solution, can anyone help?

I still don’t understand, why won’t waitforchild and findfirstchild work? I tried a method without using them and the camera still doesn’t rotate. What am I doing wrong?