Loop doesn't stop

Hello, I’m creating a main menu for my game with a background cutscene, and It doesn’t stop when the variable change.
Please, help.

wait (3)

--Services
local Tween = game:GetService("TweenService")

--Variables
local Sidebar = script.Parent:WaitForChild("Sidebar")
local Credits = script.Parent:WaitForChild("CreditsBar")
local CloseC = Credits:WaitForChild("Back")
local PlayB = Sidebar:WaitForChild("Play")
local CreditsB = Sidebar:WaitForChild("Creditsb")
local TeamsB = Sidebar:WaitForChild("Teamsb")
local ShopB = Sidebar:WaitForChild("Shopb")
local Tittle = Sidebar:WaitForChild("Tittle")
local MiniC = Sidebar:WaitForChild("Mini-Credits")
local Cam = workspace.CurrentCamera
local CamPoints = workspace:WaitForChild("Camera points")
local Cutscene = true

--Transictions

local SlideoutSlide = Tween:Create(Sidebar,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Position = UDim2.new(0,0,0,0)}):Play()
local SlideInSide = Tween:Create(Sidebar, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(-0.3, 0, 0, 0)})
local SlideInCredits = Tween:Create(Credits, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(-0.3, 0, 0, 0)})
local SlideoutCredits = Tween:Create(Credits,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Position = UDim2.new(0,0,0,0)})


-- Buttons
PlayB.MouseButton1Click:Connect(function()
	SlideInSide:Play()
	Cam.CameraType = Enum.CameraType.Custom
	Cam.FieldOfView = 70
	local Cutscene = false
end)

CreditsB.MouseButton1Click:Connect(function()
	SlideInSide:Play()
	SlideoutCredits:Play()

end)

CloseC.MouseButton1Click:Connect(function()
SlideInCredits:Play()
SlideoutSlide:Play()

end)



-- Camera

local function TweenCameraPos(Point,Speed)
	Tween:Create(Cam,TweenInfo.new(Speed,Enum.EasingStyle.Linear),{CFrame = Point.CFrame}): Play()
end			

Cam.CameraType = Enum.CameraType.Scriptable
Cam.FieldOfView = 50

while (Cutscene == true) do
    Cam.CFrame = CamPoints:FindFirstChild("1").CFrame
    TweenCameraPos(CamPoints:FindFirstChild("2"),4)
    wait(4)
    Cam.CFrame = CamPoints:FindFirstChild("3").CFrame
    TweenCameraPos(CamPoints:FindFirstChild("4"),4)
    wait(4)
    Cam.CFrame = CamPoints:FindFirstChild("5").CFrame
    TweenCameraPos(CamPoints:FindFirstChild("6"),4)
    wait(4)
    Cam.CFrame = CamPoints:FindFirstChild("7").CFrame
    TweenCameraPos(CamPoints:FindFirstChild("8"),4)
    wait(4)
end



Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

This is because you’re actually creating a new local field with the same name; this doesn’t actually point to the other Cutscene variable you have at the top of your code.

Simple fix, just get rid of the local modifier completely, like so:

Cutscene = false;

Referencing this part of your code:

- Buttons
PlayB.MouseButton1Click:Connect(function()
	SlideInSide:Play()
	Cam.CameraType = Enum.CameraType.Custom
	Cam.FieldOfView = 70
	local Cutscene = false --//There should be no local modifier here
end)

It still not working :confused:

do ‘while Cutscene do’
‘while’ works on the principle of if true and the value of Cutscene must be true to be loop.

also () is not needed

Ok, now it works, but it have got a delay.
And in that delay the order of the camera points are changed :confused:

robloxapp-20200525-2214133.wmv (3.5 MB)

try replace it with this

while Cutscene do
   for i = 1, 4 do
      if not Cutscene then break end
      Cam.CFrame = CamPoints:FindFirstChild(tostring(i + i - 1)).CFrame
      TweenCameraPos(CamPoints:FindFirstChild(tostring(i + i)),4)
      wait(4)
   end
end

With that script it doesn’t work :laughing: I’ll do a black background while transiction…

I made a mistake copy now (I didn’t give i = 1)

It works!!!
Thanks! :smiley:

1 Like