Arguments not working with tween info?

  1. What do you want to achieve?

Hi there. I am currently working on my own module service, though I’m having a problem with one of my functions.

  1. What is the issue?

I have a module function, and it looks like this:

function RevampService.BasicTween(gameObject, propertyTransform, propertyVector, numTime)
	
	local ts = game:GetService("TweenService")
	
	if numTime then
		
		ts:Create(gameObject,TweenInfo.new(numTime), {propertyTransform = propertyVector}):Play()
		
	end
	
end

Basically, you can see what I’m going for.

You can see my function call below:

rs:BasicTween(workspace.Part, "Size", Vector3.new(4, 17.126, 2), 5)

So, for some reason the actual error I’m getting has something to do with the tween info and one of my function arguments. I’m getting this error:

image

This only errors when calling the function, though the ‘numTime’ argument is being called as a number in my function call script as the codeblock above shows.

  1. What solutions have you tried so far?

I looked for the same issues on the developer forum, then went the the developer hub. Found no answers. I tried debugging but nothing.

1 Like

Have you tried printing numTime inside the module and see what it was?

An alternative solution would be to construct the entire tween info:

local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)

Yeahhhh uh…

For some reason it prints out:
image
Instead of just 5.

thats your vector 3, something is wrong with how you are inputting the parameters

You’re correct, though I don’t see what’s wrong. The arguments look fine.

consider setting the vector3 inside a variable, and then later call it by:

VectorVariable.X, VectorVariable.Y, VectorVariable.Z

or I might be wrong about this idk why the entirety of the vector 3 is becoming the numtime, idk why its being pushed back

try printing all the parameters with module and debug

Alrighty then.

characterssss

Looks like I figured it out. It has nothing to do with the function, but the game object.

For some reason the game object is nil, though you can clearly see I’m calling it here:

You need to provide EasingStyle and EasingDirection as well.

Fixed it. It was my function. I had to add a semi-colon, not a dot, though even though the number isn’t returning nil anymore, I’m still getting an error.

That is simply not true.

charsss

TweenInfo needs to know what EasingStyle you want to use. Otherwise it is not going to work. Stop wasting your time and provide them too.

Replace “:” with a period and “{propertyTransform = propertyVector}” with “{[propertyTransform] = propertyVector}” then it should work.

2 Likes

what does the error say? Idk what it says

It will automatically set the easing style and easing direction if you don’t specify it. I just fixed the actual error and now I’m getting 0 errors.

I do tweening all the time without all of the arguments nor the easing styles or easing directions.

Yeah I just fixed it lol.

charssss

Yep I did that earlier too. Don’t worry, the code is working now.

[TL;DR at the bottom of the post if you’re too lazy to read)

AH, I see what’s going on.
(Someone else has suggested this change, but an explanation would probably help)

rs:BasicTween(workspace.Part, "Size", Vector3.new(4, 17.126, 2), 5)

You’re calling the function with a colon, when you should instead use a dot. Essentially, when you call a function inside of a table using a colon, you are passing the table as the first parameter.

This is useful for OOP, where you might want to pass the object that you are trying to call a function on to the object’s metatable’s function.

However, in a non-OOP scenario like this, calling with a colon is the same as running this:

rs.BasicTween(rs, workspace.Part, "Size", Vector3.new(4, 17.126, 2), 5)

So, when the function call is received, rs is the first parameter passed.

This means that rs is called gameObject when the function executes, and part is called propertyTransform, the “Size” is called propertyVector, and the vector that you passed is called numTime.

So, what happened here is that the colon call added rs as the first argument, shifted all of the other arguments along, and 5 wasn’t received by the function whatsoever, because the vector took its place.

So when it tried to create a TweenInfo using numTime as the parameter, it actually used the Vector3 instead.

TL;DR:

Calling with a colon passed rs as the first parameter, shifting all of the other parameters along. This meant that your Vector3 took the place of numTime, so when you did TweenInfo.new, you actually passed a Vector3 as the time parameter, which was supposed to be a number.

Solution:

rs.BasicTween(workspace.Part, "Size", Vector3.new(4, 17.126, 2), 5)
1 Like