You can’t repeat until a RBXScriptSignal fires, because it will never be equal to a Boolean. The closest you can get is :Wait(), which might be a bit difficult to implement in this situation.
I’d suggest using a Boolean to control whether the loop for the camera can run or not, and when the Boolean gets set to false, the loop breaks. The Boolean will get set to false in the procedure connected to MouseButton1Click (which you could just use :Once for, if this only happens on players joining).
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local canLoop = true
task.spawn(function()
while canLoop do
--your camera code here
end
end)
local function exit()
canLoop = false
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = humanoid --CameraSubject must be a BasePart or a Humanoid, not a model.
cam.CFrame = oldpos
end
script.Parent.Frame.Play.MouseButton1Click:Once(exit)
It seems to work for awhile, but after some time passes, it switches back to the menu camera. I tried playing around with the canLoop a bit, but still I did not get to fix it, could you help me?
local cam = workspace.CurrentCamera
local oldpos = cam.CFrame
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local canLoop = true
task.spawn(function()
while canLoop do
cam.CFrame = workspace:WaitForChild("MenuCam1").CFrame
cam.CameraSubject = workspace:WaitForChild("MenuCam1")
wait(10)
cam.CFrame = workspace:WaitForChild("MenuCam2").CFrame
cam.CameraSubject = workspace:WaitForChild("MenuCam2")
wait(10)
cam.CFrame = workspace:WaitForChild("MenuCam3").CFrame
cam.CameraSubject = workspace:WaitForChild("MenuCam3")
wait(10)
cam.CFrame = workspace:WaitForChild("MenuCam4").CFrame
cam.CameraSubject = workspace:WaitForChild("MenuCam4")
end
end)
local function exit()
canLoop = false
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = humanoid --CameraSubject must be a BasePart or a Humanoid, not a model.
cam.CFrame = oldpos
end
script.Parent.Frame.Play.MouseButton1Click:Connect(exit)
I tried changing :Once() to :Connect() which also gave the same result.
It’s quite hard to fully solve this issue without drastically changing the code or adding a lot of those statements which I put in my previous post. Glad I could help, though.
Use :Once here, it just disconnects the connection after it has been used once to help preserve memory.