Brick Tweening changing position

So currently I am playing around with some code, currently this code just tweens a brick to move in a linear straight direction. Code below.

local TweenService = game:GetService("TweenService")
local part = game.Workspace.Location1
part.Position =, 0.5, -75.7)
part.Anchored = true
part.Parent = game.Workspace
part.BrickColor = BrickColor.Black()
local tweenInfo =
	4, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.In, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
for count = 1, 30 do
	local tween = TweenService:Create(part, tweenInfo, {Position =, count, 50.3)})

 -- cancel the animation after 10 seconds

What I am trying to accomplish is getting the brick to move in the type of direction below.

How would I be able to constantly change tween position, I tried to do a loop as you can see but it wont work cause it becomes nil.

1 Like

Look up the mathematical equation for a sine wave and you get the wiki answer:


I would definitely recommend a Render Step solution here. This can be accomplished fairly easily with a little sine math. Here’s what that would look like:

local RunService = game:GetService("RunService")

local step = 0.1

local connection
local increment = 0

connection = RunService.RenderStepped:Connect(function()
 increment = increment + step
 workspace.Part.Position =,math.sin(increment),increment)



Hope this helps!


Thank you so much for the help, is it possible for you to explain in a simple way of what RunService does and how it influences it here? I am new to scripting as well as tweening so understanding better would be great :slight_smile:

Sure! There’s a few things you can do with RunService, the most common use case being this RenderStepped connection. It essentially fires once per frame rendered. So if my game is at 60fps, this function fires 60 times per second. Here’s some more details on it if you want to learn more:

RunService API