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

Can I optimize this script more? If so, can you give me some idea?

local tweenservice = game:GetService("TweenService")
local top = script.Parent

local info = TweenInfo.new(
	2,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local Goals = 
{
	Position = Vector3.new(35.3, 5.388, -120.506)	
}

local tween = tweenservice:Create(top,info,Goals)

wait(5)

tween:Play()

top.Changed:Connect(function()
	top.Anchored = false
	local tweenservice = game:GetService("TweenService")
	
local info = TweenInfo.new(
	2,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
  )

    local Goals = 
   {
	Transparency = 1	
   }

    local tween = tweenservice:Create(top,info,Goals)
    tween:Play()
end)


1 answer

✓ Accepted answer

I mean, you could make that all a function

function tween(Time,Style,Direction,Properties,Object)
	local tweenService = game:GetService("TweenService")
	local Info = TweenInfo.new(Time,Enum.EasingStye[Style],Enum.EasingDirection[Direction])
	return tweenService:Create(Object,Info,Properties)
end

tween(1,"Sine","Out",{Color=Color3.fromRGB(0,255,0)},script.Parent):Play() --Example 1

tween(1,"Sine","Out",{Color=Color3.fromRGB(0,0,0)},script.Parent):Play() --Example 2

it takes tweenservice, then makes the tweeninfo out of the parameters it has, then creates a tween with the Object, Info, and the Properties. And this can be used multiple times

1 comment

0

And you can even make it a variable: local t = twen(parameters)

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