How do i shorten a tween into one line of code?

hey, i’m planning to use tweens for things in my game, but i want to have tweens shortened to one line

3 Likes

I want to know the same thing lol.

its easy but im not sure if it can be one line

game:GetService("TweenService"):Create(part,TweenInfo.new(),{property = value}):Play()

this will work i guess

4 Likes

You could wrap it in a function and call the function. That’s sort of what they’re for.

local function tween(instance, properties, info)
	info = info or TweenInfo.new()
	local tweenObject = game:GetService("TweenService"):Create(instance, info, properties)
	tweenObject:Play()
	return tweenObject
end

tween(workspace.Part, {Transparency = 1})
3 Likes

I usually do something like this, you can pass a Yield argument if you want to wait until the tween is completed before continuing as well.

local TweenService = game:GetService('TweenService')

local function Tween(Object, Info, Properties, Yield)
	local Tween = TweenService:Create(Object, Info, Properties)
	Tween:Play()
	
	if Yield then
		Tween.Completed:Wait()
	end
end

Tween(workspace.Part, TweenInfo.new(1), {Position = Vector3.new(0, 10, 0)}, true)
2 Likes

There’s usually no way you can tween more than 1 object in 1 line. You’d just have to use whatever the other devs showed above. Or you might use this:

Tween:Create(--[[ Stuff in here ]]); Tween:Create(--[[ More stuff ]])

But this just going to make the code bigger in 1 line.

Or this might be cleaner:

local TweenTable = {
    --[[
        All your tweens in here
    ]]
}

for i, tween in pairs(TweenTable) do
    tween:Play()
end

Note: I’m not sure if it will work or not since I’m not in studio right now.

Hopefully it’s clear!

local TweenService = game:GetService('TweenService')

TweenService:Create(Instance, TweenInfo.new(), {
	Size = Vector3.new(1, 1, 1),
	Position = Vector3.new(0, 0, 0)
})