Well, it doesn’t always make sense to run it if your condition isn’t met then stop it in the middle but…
Not 100% sure, what I usually do though is add checks in between stuff, obviously you shouldn’t spam it but I usually do something like:
local shouldBreak = false
while wait() do
if shouldBreak == true then break end
-- Stuff
if shouldBreak == true then break end
--More stuff
end
is there any other ways? the biggest problem is the tween delay, would i have to rewrite my code to get around that? if so can you tell me how i should?
I noticed that your coding style can be simplified:
local camera = game.Workspace.CurrentCamera
local campos = game.Workspace.CameraPos
local player = game.Players.LocalPlayer
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(12,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
local titlemusic = script.Parent:WaitForChild("TitleMusic")
local pressplay = false
titlemusic:Play()
titlemusic.Looped = true
local tweens = {
tweenservice:Create(camera,info,{CFrame = campos.Cam2.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam3.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam4.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam5.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam6.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam7.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam8.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam9.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam10.CFrame}),
tweenservice:Create(camera,info,{CFrame = campos.Cam1.CFrame})
}
script.Parent.Play.MouseButton1Click:Connect(function()
pressplay = true
print("pressed play")
end)
while wait() do
if pressplay == false then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = campos.Cam1.CFrame
for _, tween in pairs(tweens) do
tween:Play()
if pressplay == true then
tween:Cancel()
break
end
tween.Completed:Wait()
end
else break end
end
This allows you to actually check inbetween the tweens if pressplay is still true. This renders my other reply useless.