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

How can I improve the tweenservice() script?

Asked by
xsodar 19
4 years ago

Hello, anyone know how to use 1 tweenservice() several times? Let me explain:

local mP = script.Parent

local tweenService = game:GetService("TweenService")

local mpInfo = TweenInfo.new(
    15,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut,
    0,
    false,
    0
)

local mpInfoUp = TweenInfo.new(
    5,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)



local mpGoals1 = 
{
    Position = Vector3.new(-10, 1231.627, 3.75);
}
local mpGoals2 = 
    {
    Position = Vector3.new(-10, 1206.627, 3.75);
}
local mpGoals3 = 
    {
    Position = Vector3.new(-10, 1181.627, 3.75);
}

local mpGoals = 
{
    Position = Vector3.new(-10, 1261.627, 3.75);
}

local mpTween1 = tweenService:Create(mP, mpInfo, mpGoals1)
local mpTween2 = tweenService:Create(mP, mpInfo, mpGoals2)
local mpTween3 = tweenService:Create(mP, mpInfo, mpGoals3)


local mpTweenUP = tweenService:Create(mP, mpInfoUp, mpGoals)

while true do
wait(5) 
    mpTween1:Play()
wait(30)
    mpTween2:Play()
wait(30)
    mpTween3:Play()
wait(30)
    mpTweenUP:Play()
wait(30)
end

I want it to repeat the same animation but not return to the position it had at first. Because if I do as I have done in the script right now, it will work but it will take too much time and become a real mess.

Is it possible to use something else than Position = Vector3.new()? Because if I would put the part that has the animation somewhere else it will always come back to that position. I want to be able to put it anywhere on my map without changing the script all the time I change the position of the part.

Thanks for the help, Xsodar

1 answer

Log in to vote
1
Answered by 4 years ago

You can create a function with position as input to play a tween animation on a specific object.

My take:

local tweenService = game:GetService("TweenService")
local mP = script.Parent

local mpInfo = TweenInfo.new(15,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0)

local mpInfoUp = TweenInfo.new(5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)

local mpTween = function(position)
    local Tween = tweenService:Create(mP,mpInfo,{Position = position})
    Tween:Play()
end

local mpTweenUP = function(position)
    local Tween = tweenService:Create(mP,mpInfoUp,{Position = position})
    Tween:Play()
end

local mpGoals1 = {Position = Vector3.new(-10, 1231.627, 3.75);}
local mpGoals2 = {Position = Vector3.new(-10, 1206.627, 3.75);}
local mpGoals3 = {Position = Vector3.new(-10, 1181.627, 3.75);}

local mpGoals = {Position = Vector3.new(-10, 1261.627, 3.75);}

while true do
    wait(5) 
    mpTween(mpGoals1)
    wait(30)
    mpTween(mpGoals2)
    wait(30)
    mpTween(mpGoals3)
    wait(30)
    mpTweenUP(mpGoals)
    wait(30)
end
Ad

Answer this question