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

Part moves from 1 to the other, 1 of the parts move but it doesn't work, Help?

So basically, Im making a minigame and i want a part to move from 1 place to the other

local TweenService = game:GetService("TweenService")
local Start = game.Workspace:WaitForChild("Start")
local End = game.Workspace:WaitForChild("End")

local PartToMove = game.Workspace:WaitForChild("PartToMove")
local TweenInformation = TweenInfo.new(
    0.5, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.InOut, -- Easing Direction
    5, -- Repeat Count
    true, -- Reverses to initial position? (true/false)
    1 -- Delay between each tween.
)
--[[ 
local EndProperties = {
    Position = Vector3.new(X,Y,Z)
} 

local EndProperties = {
    Position = End.Position
}

--]]
local EndProperties = {
    Position = End.Position    
}

local TweenToPlay = TweenService:Create(PartToMove,TweenInformation,EndProperties)

while true do
    TweenToPlay:Play()
    wait(6) -- After the Tween is finished it will stop for 6 seconds then replay.
end

The script above works besides 1 little thing, I want the part named End to move, But not by tweening just teleporting. When i do this, The moving part doesn't change, It continues from going from start to where End USED to be. How can i make it update?

(The script was made by JakyeRU on the Dev forums. https://devforum.roblox.com/t/how-do-i-make-an-object-move-from-one-point-to-another/263127/3 )

2 answers

If you want to move part to another part's location. Just Simply change the end's CFrame.

local part = yourpart
local endPart = yourpart - - This is where the part end be

part.CFrame = endPart.CFrame

Everything for the tween is kept constant throughout your code, so you would have to update the tween when you're about to do a new one (i.e: in the while loop). To better the code, you can use Tween.Completed:Wait(), which yields the while loop until the tween has completed, so that you can wait 6 seconds to replay the tween better accurately

while true do
    local End_Goal = {Position = End.Position}
    local TweenInformation = TweenInfo.new(
        0.5, -- Time
        Enum.EasingStyle.Linear, -- EasingStyle
        Enum.EasingDirection.InOut, -- Easing Direction
        5, -- Repeat Count
        true, -- Reverses to initial position? (true/false)
        1 -- Delay between each tween.
    )

    local Tween = TweenService:Create(PartToMove, TweenInformation, End_Goal)
    Tween:Play()
    Tween.Completed:Wait()
    wait(6)
end

With this, it won't stop going to where the end part originally was, instead, it will go to where it is now at the point in time where it is ready to initiate a tween

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