Why is my camera not tweening?

The camera just wont tween, i need help, ive been trying for a little bit now

game:GetService("RunService").RenderStepped:Connect(function()
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamMid.CFrame}):Play()
		wait(15)
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamEnd.CFrame}):Play()
		wait(15)
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamMid.CFrame}):Play()
		wait(15)
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamStart.CFrame}):Play()
		wait(15)
	end)

Any help is appreciated!

try using print() statement to debug

Why are you using RenderStepped for this? It will not yield the Event, and will just spam the code you have.

2 Likes

yes, I guess that’s causing the issue, use while true loop @Ardent_17

see if this works

local TS = game:GetService("TweenService")
local WS = game:GetService("Workspace")

local Camera = WS:WaitForChild("Camera")
local TitleScreen = WS:WaitForChild("TitleScreen")
local Info = TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)

while true do
	Camera.CameraType = Enum.CameraType.Scriptable

	local MidTween1 = TS:Create(Camera, Info, {CFrame = TitleScreen.TitleCamMid.CFrame})
	MidTween1:Play()
	MidTween1.Completed:Wait()

	local EndTween = TS:Create(Camera, Info, {CFrame = TitleScreen.TitleCamEnd.CFrame})
	EndTween:Play()
	EndTween.Completed:Wait()

	local MidTween2 = TS:Create(Camera, Info, {CFrame = TitleScreen.TitleCamMid.CFrame})
	MidTween2:Play()
	MidTween2.Completed:Wait()

	local StartTween = TS:Create(Camera, Info, {CFrame = TitleScreen.TitleCamStart.CFrame})
	StartTween:Play()
	StartTween.Completed:Wait()
end

Your Code should work, but its very weird to look at because you arent using Variables, you should do this to make it easier for you, and for you to understand better, It also makes your code slower than normal, so adding variables would help with making it more efficient.

Your Code is something that you a Beginner would do, and the code can be simplified from Multiple Lines, to just a couple of Lines.
The Code @KultDeeri Provided can also be Simplified, and Generally isnt a good way to be writing code, its long, and pretty much unnessacary at some points.

Here is how you can Clean up up your Code: (if you want to look at the revision I did)

-- Services on Top

-- The Services can be used to help you with Specific Tasks
-- Like with RunService to run code during gameplayer, or
-- TweenService, to Interpolate an Object Smoothly.

local TweenService = game:GetService("TweenService") -- TweenService
local RunService = game:GetService("RunService") -- RunService

-- Components here

-- The Components or Main Variables area is for you to place your
-- Important Variables that will be used 

local Camera = workspace.CurrentCamera -- Variable to Access our Camera
local Screen = workspace:WaitForChild("TitleScreen") -- Waits for Object 'TitleScreen'

local Info = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) -- TweenInfo

local Sequence = {"TitleCamMid", "TitleCamEnd", "TitleCamMid", "TitleCamStart"} -- THis is just to store the Names of Items so we can loop through them.

-- functions (if you have any)

-- Store functions here that you have use for specific purposes
-- so you dont rewrite code over and over again

-- code
for i = 1, #Sequence do -- Loops for how many Items are in a Table
    local SeqString = Sequence[i] -- Gets a String Based on the Order Given using the index to get the string
    TweenService:Create(Camera, Info, {CFrame = Screen[SeqString].CFrame}):Play() -- Creates Tween with Corresponding Data
    task.wait(15) -- better / more performant version of wait()
end

As you can see for the Tweening,

This
And This

Has just Became this:

local Sequence = {"TitleCamMid", "TitleCamEnd", "TitleCamMid", "TitleCamStart"}

for i = 1, #Sequence do -- Loops for how many Items are in a Table
    local SeqString = Sequence[i] -- Gets a String Based on the Order Given using the index to get the string
    TweenService:Create(Camera, Info, {CFrame = Screen[SeqString].CFrame}):Play() -- Creates Tween with Corresponding Data
    task.wait(15) -- better / more performant version of wait()
end

A Better Alternative than writing so much.


Another thing is your Script Placement, or Script Usage.

You have to Keep in mind that Scripts are used for specific purpose, and are limited in placements.

For this Purpose, you have to use a LocalScript to Handle this Data for the Player, LocalScripts Documentation Covers where you can place this script, Its very Specific on where as because if you dont place it in the correct Area, It will not work at all:

1 Like

I’ve only done it like that way so that he can understand it. I wouldn’t just fully rewrite his script into a different method. The only thing I’ve done is add variables for him and that’s all. But otherwise your method is good. By the way, you also forgot to put the for loop inside in a loop.

It does not require a loop to function, unless you want it to repeat itself right after, than there is no use for it.

Also, Its not a Different System, Its a Simplified System of his code that you can easily write.

forgot to mention, this script is completely out of context as i rushed to post this.

game:GetService("RunService").RenderStepped:Connect(function()
	if _G.titleCamActive == true then
		
		if _G.titleCamActive == false then return end
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamMid.CFrame}):Play()
		wait(15)
		if _G.titleCamActive == false then return end
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamEnd.CFrame}):Play()
		wait(15)
		if _G.titleCamActive == false then return end
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamMid.CFrame}):Play()
		wait(15)
		if _G.titleCamActive == false then return end
		game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = workspace.TitleScreen.TitleCamStart.CFrame}):Play()
		wait(15)
		if _G.titleCamActive == false then return end
	end) end)

its very messy, but it did work before. I have a separate script with the _G.titleCamActive variable changing so it would start and stop when on the titlescreen or not.

Also, I had to loop because i wanted it to keep going back and forth forever depending if the variable was active or not.

You shouldn’t be using _G, you should be using ModuleScripts instead.

Yes, I know it is bad practice now, but when i started this project i made alot of the main logic and such with _G.

What would a better way to make a title screen cam be? Like how would I make it so I can rotate it around a part or something instead of tween? Because stopping a tween is buggy at best sometimes.

You can use Trignonometric functions like math.sin, math.cos, or math.tan, and their inverse functions

I do wanna get used to single script architecture, but I havent seen many tutorials or places to start with it.

I also get worried with it, because if there is just one error, wouldn’t everything stop working?

Just used your script to test and changed the _G.titleCamActive

game:GetService("RunService").RenderStepped:Connect(function()
	local TweenService = game:GetService("TweenService")
	local RunService = game:GetService("RunService")
	local Camera = workspace.CurrentCamera
	local Screen = workspace:WaitForChild("TitleScreen")

	local Info = TweenInfo.new(10, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

	local Sequence = {"TitleCamMid", "TitleCamEnd", "TitleCamMid", "TitleCamStart"}
	if titleCamActive == true then
		Camera.CameraType = Enum.CameraType.Scriptable
		for i = 1, #Sequence do
			if titleCamActive ~= true then return end
			local SeqString = Sequence[i]
			TweenService:Create(Camera, Info, {CFrame = Screen[SeqString].CFrame}):Play()
			task.wait(15)
		end
	end 
end)

It still just doesn’t tween. Weirdest part is, if I go on a script while game is still running, depending on how long Im not focused on the game, it will tween towards the titlecammid part. Once it reaches though, it wont tween anywhere else no matter what. Print() works as well.

EDIT: Just tested, i lowered the speed from 10 to 1, and it tweened extremely slowly to the titlecammid. Then it just did not tween anywhere else.

EDIT2: Just removed this line :

if titleCamActive == true then

and

if titleCamActive ~= true then return end

And the exact same thing happened, So i truly am lost here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.