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.
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)
Oh yeah, I remember now. I forgot a lot of things after my break. I’ll redo my code and message you asap if anything happens. Thanks for replying
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
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
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.
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
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?