Script Not Looping

Hello so I just made this camera script and I want it to keep running until a button is pressed but it’s not working.


local Camera = game.Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = workspace.startPos
Camera.CFrame = workspace.startPos.CFrame
Camera.Focus = workspace.endPos.CFrame

Camera:Interpolate(workspace.endPos2.CFrame, workspace.startPos2.CFrame, 10) 
wait(10)
Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid 
Camera.CameraType = Enum.CameraType.Custom

repeat until game.StarterGui.Lobby.ButtonBackMain.Play.MouseButton1Click  -- I also put other events here instead of MouseButton1Click and non work.

Please help, I’m not that good at camera manipulation. And I’m not getting any error’s in the output, syntax and script analysis. I don’t understand why it’s not working.

1 Like

for the last line I would say,

game.StarterGui.Lobby.ButtonBackMain.Play.MouseButton1Click:Wait()

and also remove the “repeat until” part

start with that and tell me how it goes.

Ok I tried it and doesn’t work.

Oh, now I understand your problem a lot better now

Okay, let me propose another solution to you:

-- assuming that this is a local script

local Camera = game.Workspace.CurrentCamera
local debounce = false -- cooldown variable
local camera_interpolated = false

local function interpolate_camera() -- function to interpolate the camera
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CameraSubject = workspace.startPos
    Camera.CFrame = workspace.startPos.CFrame
    Camera.Focus = workspace.endPos.CFrame
    Camera:Interpolate(workspace.endPos2.CFrame, workspace.startPos2.CFrame, 10)
    wait(10)
    camera_interpolated = true
end

local function undo_interpolation() -- function to undo the camera's effects
    Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    Camera.CameraType = Enum.CameraType.Custom
    camera_interpolated = false
    wait(1)
end

game.StarterGui.Lobby.ButtonBackMain.Play.MouseButton1Click:Connect(function() -- this runs whenever the button is clicked
    if not debounce then
        debounce = true
        if not camera_interpolated then
            interpolate_camera()
        else
            undo_interpolation()
        end
        debounce = false
    end
end)

try using this script and see if your problem is solved

Ok, I’ll try it out. My Roblox studio is not opening so I’ll tell you if it works, once it starts working. Thanks!

1 Like

Side note, but this should belong in #help-and-feedback:scripting-support

Also you’re getting the StarterGui, which is not working cause that’s replicated to the server side

Adding onto the code that Jonesloto sent earlier, try this:

-- assuming that this is a local script

local Camera = game.Workspace.CurrentCamera
local debounce = false -- cooldown variable
local camera_interpolated = false
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local LobbyFrame = PlayerGui:WaitForChild("Lobby")

local function interpolate_camera() -- function to interpolate the camera
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CameraSubject = workspace.startPos
    Camera.CFrame = workspace.startPos.CFrame
    Camera.Focus = workspace.endPos.CFrame
    Camera:Interpolate(workspace.endPos2.CFrame, workspace.startPos2.CFrame, 10)
    wait(10)
    camera_interpolated = true
end

local function undo_interpolation() -- function to undo the camera's effects
    Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    Camera.CameraType = Enum.CameraType.Custom
    camera_interpolated = false
    wait(1)
end

LobbyFrame.ButtonBackMain.Play.MouseButton1Click:Connect(function() -- this runs whenever the button is clicked
    if not debounce then
        debounce = true
        if not camera_interpolated then
            interpolate_camera()
        else
            undo_interpolation()
        end
        debounce = false
    end
end)

it works but it doesn’t start interpolating until the player hits the play button, I want it do that it does that when the player joins and as soon as they hit the play button they will spawn.

Oh I fixed it, you forgot to call the functions

 undo_interpolation() and interpolate_camera()

also interpolate_camera() and debounce weren’t supposed to run.

All I just did was fix the major things that I saw, you’d prob need to configure the script around a bit

Repeat is a type of loop.
So you need to wrap the code you want to loop between repeat and until like this:

repeat
print("Hello world") -- put whatever you want to repeat here
until false -- put your condition here
2 Likes

Got you, thanks for the clarification. @Jackscarlett @Jonesloto Thanks also to both of you for the help.

1 Like

Woah woah, you marked your own post as a solution? This was not the solution to the problem, this was: Script Not Looping - #6 by Jackscarlett . Please give the post author credit for the solution, don’t hog it for yourself.

I did, lol. I just marked mine for the time being so I could tell him about my issue.

I was just revamping the code, it’s not mine

Here’s the OG post:

Ok, I marked @Jonesloto As the final solution @iamtryingtofindname Also, it was Jonesloto to did the original post.