The Script is working, when i fire the Event with true and then with false it will break the while after the Tween is finished (50 Sec).
But when i fire the Event with true and then with false and fire it again true before the Tween is finished the latest loop will run forever.
The Break will just work for one while Loop.
And I wrote in the script “tweenCreate:Cancel()” this is breaking the Tween but the cutsceneTime will run anyway.
I tried with cutsceneTime = 0, it didnt worked, does anybody know how could i do it if u know what i mean.
local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local introCameras = game.Workspace:WaitForChild("IntroCameras")
local breakCamera = false
function tween(part1,part2,cutsceneTime)
local tweenInfo = TweenInfo.new (
cutsceneTime,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
camera.CFrame = part1.CFrame
local tweenCreate = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
tweenCreate:Play()
game.ReplicatedStorage:WaitForChild("CameraMenuAnimation").Event:Connect(function(trueOrFalse)
if trueOrFalse == false then
breakCamera = true
tweenCreate:Cancel()
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end
end)
task.wait(cutsceneTime)
end
game.ReplicatedStorage:WaitForChild("CameraMenuAnimation").Event:Connect(function(trueOrFalse)
if trueOrFalse == true then
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
end
while task.wait() do
if breakCamera == false then
tween(introCameras.IntroCamera2, introCameras.IntroCamera3, 50)
if breakCamera == true then
breakCamera = false
break
end
tween(introCameras.IntroCamera3, introCameras.IntroCamera2, 50)
if breakCamera == true then
breakCamera = false
break
end
end
end
end
end)
You can use Tween:Cancel().
I’d also use workspace.CurrentCamera instead of game.Workspace.Camera.
Tweening in a continuous loop will not yield, meaning the running thread will not pause and wait for the tween to finish. If the mentioned behavior isn’t intentional, consider creating a debounce to prevent the tween from playing again whilst already playing, and stop tweens using the mentioned Tween:Cancel().
Fun fact, Tween:Wait() either personally gives me trouble or isn’t functional some of the time, so I use my custom function.
local YieldForTween = function(Instance, Properties, ...)
local Tween = TweenService:Create(Instance, TweenInfo.new(... or 0.1), Properties); Tween:Play();
repeat task.wait() until Tween.Completed:Wait();
end;
print(1);
YieldForTween(Part, {Size = Vector3.Zero}, 1); -- Waits for tween to finish more accurately.
print(2);
It’s always best to stick to the practices provided by the API.
Exploiters may consider tampering with game.WaitForChild using hookmetamethod to fool the script.
But i want that the Tween Stop directly, after i saying Tween:Cancel() the cutszeneTime kept running for 50 sec and then the loop will break and when the CameraMenuAnimation Event fires again in the 50 sec the second Loop will never Stop
Read the “–” Markers then i hope if i explained it good u know what i mean, its long
local TweenService = game:GetService("TweenService")
local camera = game.Workspace.Camera
local introCameras = game.Workspace:WaitForChild("IntroCameras")
local breakCamera = false
function tween(part1,part2,cutsceneTime)
local tweenInfo = TweenInfo.new (
cutsceneTime,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
camera.CFrame = part1.CFrame
local tweenCreate = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
tweenCreate:Play()
game.ReplicatedStorage:WaitForChild("CameraMenuAnimation").Event:Connect(function(trueOrFalse) -- Stopping Camera Tween
if trueOrFalse == false then
breakCamera = true -- This will break the Loop
tweenCreate:Cancel() --Cancel the Tween (cutsceneTime will not stop after that and will run anyway)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end
end)
task.wait(cutsceneTime)
end
game.ReplicatedStorage:WaitForChild("CameraMenuAnimation").Event:Connect(function(trueOrFalse) -- Playing Camera Tween
if trueOrFalse == true then -- trueOrFalse is "true", the script will run, would it be "false" the Event over me inside the tween function would start, what would stop the tween.
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
end
while task.wait() do
tween(introCameras.IntroCamera2, introCameras.IntroCamera3, 10) -- Tween need 10 sec to tween from Part 1 to Part 2
if breakCamera == true then -- If trueOfFalse is "false" the Event over me inside the tween function will run, what will make breakCamera to true. If its true the Loop will break. But there is a Problem. If a Tween is running and another Event with trueOrFalse == true is firing this loop will start again. Now are 2 Loops running. After the first Loop is breaked because of the "If breakCamera == true", the second one will not break because breakCamera is false. It would work if i put local breakCamera into this Event and not outside the Event, but then i cant change the breakCamera outside the script.
breakCamera = false
break
end
tween(introCameras.IntroCamera3, introCameras.IntroCamera2, 10)
if breakCamera == true then
breakCamera = false
break
end
end
end
end)
I thing one Problem here is that local breakCamera will be false and that means that the other Loops will not break the Loop but how can i make seperate variables then? Idk
--/// Services:
local ReplicatedStorage = game:GetService('ReplicatedStorage');
local TweenService = game:GetService('TweenService');
local Workspace = game:GetService('Workspace');
--/// Constants:
local Camera = Workspace.CurrentCamera;
local CameraMenuEvent = ReplicatedStorage:WaitForChild('CameraMenuAnimation')
local IntroCameras = Workspace:WaitForChild('IntroCameras');
--/// Variables:
local BreakCamera = false;
--/// Local Functions:
local Tween = function(CFrame1: Cframe, CFrame2: CFrame, Time: Number)
local TweenInformation = TweenInfo.new(Time, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut);
local TweenCreate = TweenService:Create(Camera, TweenInformation, {CFrame = CFrame2});
Camera.CFrame = CFrame1;
TweenCreate:Play();
local Function = function(Boolean: Boolean) print(Boolean);
if Boolean then return end;
BreakCamera = true;
TweenCreate:Cancel();
Camera.CameraType = Enum.CameraType.Custom;
end;
return CameraMenuEvent.Event:Connect(Function);
end;
local Function1 = function(Boolean: Boolean) print(Boolean);
if not Boolean then return end;
local IntroCamera2, IntroCamera3 = IntroCameras:WaitForChild('IntroCamera2'), IntroCameras:WaitForChild('IntroCamera3');
if Camera.CameraType ~= Enum.CameraType.Scriptable then
Camera.CameraType = Enum.CameraType.Scriptable;
end;
while task.wait() do
Tween(IntroCamera2.CFrame, IntroCamera3.CFrame, 10);
if BreakCamera then
BreakCamera = false;
break;
end;
Tween(IntroCamera3.CFrame, IntroCamera2.CFrame, 10);
if BreakCamera then
BreakCamera = false;
break;
end;
end;
end;
--/// Connections:
CameraMenuEvent.Event:Connect(Function1);