[Help on Scripting] Moving Block Code Isn't Working

Made a moving block code… Doesn’t work for some reason, checked more than 5 times.
Changed the code a few times. Do not know what I am doing wrong.

function move(x,y,z)
for i=1,5 do
script.Parent.Position = script.Parent.Position + Vector3.new (x,y,z)
wait(0.1)
end
end

while true do
move(0, -1, 0)
move(0, -1.5, 0)
move(0, 1.5, 0)
move(0, 1, 0)

end

You can achieve your goal using TweenService.

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

local info = TweenInfo.new(
10, -- how long the tween will take
Enum.EasingStyle.Linear, -- How the tween will play
Enum.EasingDirection.Out, -- which way itll go
5, -- how many times itll repeat
true, -- if you want it to repeat
1 -- delay time
)

local goal = {Position = Vector3.new()}

local tweening = TweenService:Create(part, info, goal)

tweening:Play()

If the code doesnt work try watching a tutorial. I havent used tweening in weeks so i am pretty rusty.

Good idea! I will try it! Thanks!

It works! Thanks a lot!
:smile:

If it worked, please mark my post as a solution :slight_smile:

FYI this can be achieved with two ways and they are simple:

The first is using TweenService, here’s it’s API Reference: TweenService API Reference

The second one is using the Lerp function, here’s how to use it on Vector3 for example:

Vector3Lerp