So I’ve been trying to make that Camera animation on the background, and I’m stuck here.
When I hit “play”, the Camera doesn’t reset back to the player’s head.
Tried searching, nothing worked.
Here’s my code:
-- Defining Stuff
local camera = game.Workspace.CurrentCamera
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(25)
local TC = { CFrame = CFrame.new(Vector3.new(-150.3, 24.099, 29.589)) * CFrame.Angles(0, math.rad(90), 0) }
TW = TS:Create(camera, TI, TC)
local stopPlaying = false
-- Changing initial Camera Type
camera.CameraType = Enum.CameraType.Scriptable
-- Repeating Background Animation
repeat
print(script.stopPlaying.Value)
camera.CFrame = CFrame.new(Vector3.new(86.1, 24.099, 29.589)) * CFrame.Angles(0, math.rad(90), 0)
TW:Play()
wait(25)
until script.stopPlaying.Value == true
-- Function to Stop Playing.
function onCalled()
script.stopPlaying.Value = true
print(stopPlaying)
local character = game.Players.LocalPlayer.Character
camera.CameraSubject = character.Humanoid
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = character.Head.CFrame
TW:Cancel()
local TW2 = TS:Create(camera, TweenInfo.new(0.1), {CFrame = character.Head.CFrame})
TW2:Play()
end
As @CompilerError mention, tweenservices have a built in :Pause() and :Cancel() function built in, it should also be classified you MUST have this have the tween itself defined preferrably by a local function in the script.
I feel really dumb. As I was reading my code, I noticed that my function that stopped the repeat loop was… after the repeat loop, so it didn’t run. Thanks for helping anyways.
Thank you for using devforum help section, if you need any further help with programming and/or any developer related questions, please do not hesitate to open another post and our developers will help you to the best of the best of their abilities,