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

Why my Part is not moving correctly with Tween service?

Asked by 4 years ago
Edited by User#5423 4 years ago

Hello i wanted to make a cave and i noticed it was dark.So I had a idea of putting a spotlight inside a Part too make it brighter then I wanted to make it move back and forth in the cave in a line.

I watched a video on Tweenservice and it worked my part did move but not in a strait line forward.For some reason my Part moved forward and down but i only made it so that it should only move x.Is it heading towards something?

script -

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

local Info = TweenInfo.new(
   5,
   Enum.EasingStyle.Linear,
   Enum.EasingDirection.In,
 -1,
 true,
   0
   )


local Goals =                  
{
    Position = Vector3.new(10,0,0); -- i want it to only move the x position but i moves all of them?

}

local movepartx = TweenService:Create(part, Info, Goals)
wait(1)
movepartx:Play()
0
put it in a code block for god sake Gameplayer365247v2 1055 — 4y
0
Please put a block gode in goddamnit maxpax2009 340 — 4y
0
whats a code block? thebananashetoldyou 31 — 4y
0
When you press LUA icon there is two line of ~~~~ Put the code inside (not outside) that 2 time of ~~~~~ Nguyenlegiahung 1091 — 4y
0
edit:- fixed codeblock User#5423 17 — 4y

1 answer

Log in to vote
1
Answered by
Nanomatics 1160 Moderation Voter
4 years ago

Okay, you had one problem when you were setting the goal, you were setting the part to be positioned as Vector3.new(10, 0, 0). What you need to do is add 10 studs on the X Axis to the position it is already in for it to work properly.

It should look like this:

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

local Info = TweenInfo.new( 5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, true, 0)

local partPos = part.Position
local Goals =
{ 
    Position = partPos + Vector3.new(10,0,0)
}

local movepartx = TweenService:Create(part, Info, Goals)
wait(1)
movepartx:Play()

Note: please never post your code without being in code blocks, it's very annoying and hard to read.

I hope I helped, please let me know if you have further questions.

0
sorry and i understand it better now i was exposed to add the position not set it thebananashetoldyou 31 — 4y
Ad

Answer this question