Shortening the script

``local part = script.Parent

``while true do

part.Position = Vector3.new(0.05,10,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.01,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.02,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.03,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.04,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.05,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.06,-10)

wait(0.3)

part.Position = Vector3.new(0.05,10.07,-10)

end ``

this can be a long script, do you know a way to shorten it?

You could try using a for loop, or you could try tweening the part.

Try for loops:

while true do
for i = 10,10.07,0.01 do
      part.Position = Vector3.new(0.05,i,-10)
     wait(0.3)
end
end

yes i am using a loop, i was gonna add more though

[edit] didn’t notice the outer while-loop

local part = script.Parent
local start = 10
local stop = 10.07
local increment = 0.01
while (true) do
    for i = start, stop, increment do
        part.Position = Vector3.new(0.05, i, -10)
        wait(0.3)
    end
end
1 Like

while true do
part.Position = Vector3.new(0.05, part.Position.Y + .01, -10)
wait(0.3)
end

1 Like

This isn’t a for loop, this i a while loop that will run for a infinite time.

I didn’t know if he wanted it to keep going or…

just use a tween.

local TweenService = game:GetService("TweenService")
local repeatCount = 5
local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, repeatCount)
local tweenGoal = {Position = Vector3.new(0.5, 10.1, -10)

local tween = TweenService:Create(part, tweenInfo, tweenGoal)
tween:Play()
1 Like

[Workspace.Part.Script:6: Expected ā€˜}’ (to close ā€˜{’ at line 4), got ā€˜local’]

He forgot a }, Put this:

local TweenService = game:GetService("TweenService")
local repeatCount = 5
local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, repeatCount)
local tweenGoal = {Position = Vector3.new(0.5, 10.1, -10)}

local tween = TweenService:Create(part, tweenInfo, tweenGoal)
tween:Play()
1 Like

Can be reduced to this, and still be readable:

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 5)
TweenService:Create(part, tweenInfo, {Position = Vector3.new(0.5, 10.1, -10)}):Play() -- This is what I normally do in my scripts.

You should give @TheTurtleMaster_2 the solution. It solves your problem.

generally i’d just tell you to use TweenService for that instead

1 Like