Hey!
I’ve got a main menu in my game Réimse Ársa that I’m having trouble getting to loop properly.
I currently have it set up where on my main menu, the player will click “Enter”, a teleportation options menu will pop up, and their camera will be returned accordingly once they choose a location, which all currently works great!
My current ISSUE is that I have multiple “scenes” that the camera pans through while the player sits on the main menu. They should be looping through, but somehow it’s looping weird and isn’t actually “looping” for a lack of better terms.
Script Locations and Script
local tween = game:GetService("TweenService")
local orange = workspace.Camera
local scenes = workspace.CameraScenes
local currentTween = nil
local looping = true
repeat wait() until orange.CameraSubject ~= nil
orange.CameraType = Enum.CameraType.Scriptable
--Play button
script.Parent.MouseButton1Click:Connect(function()
orange.CameraType = Enum.CameraType.Custom
looping = false
currentTween:Pause()
end)
--Scenes
while looping do
for i, v in pairs(scenes:GetChildren()) do
if looping == false then return end
orange.CFrame = v["1"].CFrame
currentTween = tween:Create(orange, TweenInfo.new(10), {CFrame = v["2"].CFrame})
currentTween:Play()
wait(10)
end
end
The camera is named orange because naming it cam wasn’t working for whatever reason.
Video of the Issue
Showing the parts at the end of the video is just me showing that one of my scenes isn’t working, and that there isn’t a pair of parts anywhere underneath the water for the script to pull from.
I got this code from a comment under this Tutorial on YouTube by Jersito4 that was working-ish. I did a bit of reading on here to see if maybe there was a fix for my issue and read a lot of comments that pairs is deprecated now? Not sure.
Any help is appreciated. <3
1 Like
First off, the animation looks really cool. wait()
is deprecated; switch to task.wait()
instead (the reason for it is explained here). pairs
is not essentially deprecated, it’s just not necessary to implement the pairs
iterator on the loop, because the loop automatically knows how’s the table syntax and iterates accordingly.
The final code would be something like that:
local TS = game:GetService("TweenService")
local orange = workspace.Camera
local scenes = workspace.CameraScenes
local currentTween
local looping = true
while not orange.CameraSubject do -- Changed to while loop because it first checks for the CameraSubject and if it is nil, loops through, differently from repeat, which doesn't check for the condition before entering the loop.
task.wait()
end
orange.CameraType = Enum.CameraType.Scriptable
--Play button
script.Parent.MouseButton1Click:Connect(function()
orange.CameraType = Enum.CameraType.Custom
looping = false
if not currentTween then return end
currentTween:Pause()
end)
--Scenes
while looping do
for _, scene in scenes:GetChildren() do
if not looping then return end
orange.CFrame = scene["1"].CFrame
currentTween = tween:Create(orange, TweenInfo.new(10), {CFrame = scene["2"].CFrame})
currentTween:Play()
currentTween.Completed:Wait()
end
end
EDIT: Removed the wait(10)
because it’s more precise using the tween’s Completed
event.
1 Like
Thanks, glad you like the animation. I’m really liking how things are coming along as well so this is validating!!
So I tried your script, and the camera no longer pans across from Part 1 to Part 2. It just kinda sits at Part 1 on whichever scene it picks and doesn’t switch to the next.
I’m really not Lua literate so I’m not super sure where it went wrong (unless it has something to do with pairs after all?)
Thanks for your help, I really appreciate your time.
1 Like
OHH, I’m sorry, I forgot to change the tween variable to TS.
local TS = game:GetService("TweenService")
local orange = workspace.Camera
local scenes = workspace.CameraScenes
local currentTween
local looping = true
while not orange.CameraSubject do -- Changed to while loop because it first checks for the CameraSubject and if it is nil, loops through, differently from repeat, which doesn't check for the condition before entering the loop.
task.wait()
end
orange.CameraType = Enum.CameraType.Scriptable
--Play button
script.Parent.MouseButton1Click:Connect(function()
orange.CameraType = Enum.CameraType.Custom
looping = false
if not currentTween then return end
currentTween:Pause()
end)
--Scenes
while looping do
for _, scene in scenes:GetChildren() do
if not looping then return end
orange.CFrame = scene["1"].CFrame
currentTween = TS:Create(orange, TweenInfo.new(10), {CFrame = scene["2"].CFrame})
currentTween:Play()
currentTween.Completed:Wait()
end
end
My bad 
EDIT: Now this might work.
1 Like
Oops! LOL
It’s panning now! But its still having the same original issue where there’s a random scene which doesn’t technically exist. It also still isn’t playing Scene 1 (the waterfall/bridge moment) if it doesn’t start on it.
Is that because scenes:GetChildren() returns the first scene and the second scene, and when the camera TPs to the second first scene it changes its orientation?

1 Like
This is probably because the scene parts are rotated. When you make camera.CFrame = object.CFrame, the camera also changes its orientation based on the object.CFrame.
1 Like
I think I understand what you’re talking about.
Scene 1 parts 1 and 2 are facing the same direction, as is Scene 2’s parts 1 and 2. Is it because the scenes themselves are facing two different directions (i.e. north and east)? I haven’t rotated them to look up or down, only left or right if that makes sense.
Try to change the camera.CFrame to face the LookVector of the parts, so the camera doesn’t randomly looks down. It appears that the camera is looking down, so it aims to the water fountain down the scene parts of the second scene.
1 Like
Wait a minute, are the parts anchored?
2 Likes
Oh my god.
Why does it ALWAYS seem to be the anchor that’s the issue!? I’m so dumb.
Scene 1’s parts were not anchored so they were falling into the river below. THANK YOU SO MUCH LOL.
1 Like
Nahh, that’s fine
. I’m always forgetting to anchor parts, too! Good luck with your game, it looks really fantastic so far, including the UI!
1 Like