Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why my TweenService Camera doesn't work?

I got to make a MapVoter with the ViewportFrame, I want to view the map in the panel. As this twitt

Err:

10:19:34.472 - ServerScriptService.Scripts.VPR_GameScript:212: attempt to call a userdata value

Code:

Camera.CFrame = Cinematic.Elements.Cam1.CFrame

TweenService:Create(Camera, TweenInfo.new(Settings.VoteTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)

{CFrame = Cinematic.Elements.Cam2.CFrame}) -- line 212

Why I can't set the CFrame of my camera?

1 answer

✓ Accepted answer

Look CLOSELY at this line:

Camera.CFrame = Cinematic.Elements.Cam1.CFrame

TweenService:Create(Camera, TweenInfo.new(Settings.VoteTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)

{CFrame = Cinematic.Elements.Cam2.CFrame})

Still don't see it?

TweenService:Create(Camera, TweenInfo.new(Settings.VoteTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true){CFrame = Cinematic.Elements.Cam2.CFrame})

You're trying to call the TweenInfo object returned by TweenInfo.new!

Remember that when you are calling a function, parentheses are optional if the first argument is a string or table literal, but it only works for one argument.

That is, the following examples are valid:

fn"string";
fn{...}; --// some table with elements

But these are not:

local s = "string";
local t = {...};

fn s
fn t

fn"string", ...; --// some other arguments, but this is not valid

This is syntactic sugar for a function call. Lua just thought that this was sugar for a function call.

TweenService:Create(Camera, TweenInfo.new(Settings.VoteTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true), {CFrame = Cinematic.Elements.Cam2.CFrame})

You forgot your comma to separate the arguments.

I personally like having the tweenInfo in a variable, so it gets less messy. This also allows to reuse it with ease if you need to


Sort of like this:

local info = TweenInfo.new(...); --// put stuff here
local tween = TweenService:Create(Camera, info, {CFrame = Cinematic.Elements.Cam2.CFrame});

tween:Play(); --// *play* the tween

This discussion is preserved as it was. New answers, comments, and votes are closed.