Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

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

0
And you can even make it a variable: local t = twen(parameters) blockmask 374 — 5y
Ad

Answer this question