How would I make a flying part move in a up/down pattern?(Using BodyVelocity)

I have a part that flies foward but I want it to do an up/down pattern. How would I do that?
Any help is appreciated :+1:
This script makes the part fly forward:

local remote = game.ReplicatedStorage:WaitForChild("Touched")
remote.Event:Connect(function()
	local FlyingModel = game.ReplicatedStorage:WaitForChild("FlyingModel")
	local clone = FlyingModel:Clone()
	wait(1)
	clone.Parent = workspace
	local y = Instance.new("BodyVelocity")
	y.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	y.Velocity = clone:WaitForChild("HumanoidRootPart").CFrame.lookVector*50
	y.Parent = clone:WaitForChild("HumanoidRootPart")
end)

Just something quick so you can get an idea of something to try. You can adjust the wait time in the loop to speed or slow it down as well as the YAdjust size. Also the 1 can be adjust if you want to increase the Y up and down range.

local remote = game.ReplicatedStorage:WaitForChild("Touched")
remote.Event:Connect(function()
	local FlyingModel = game.ReplicatedStorage:WaitForChild("FlyingModel")
	local clone = FlyingModel:Clone()
	wait(1)
	clone.Parent = workspace
	local y = Instance.new("BodyVelocity")
	y.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	y.Velocity = clone:WaitForChild("HumanoidRootPart").CFrame.lookVector*50
	y.Parent = clone:WaitForChild("HumanoidRootPart")

    task.spawn(function()
        local Y = clone.PrimaryPart.Position.Y
        local initialY = Y
        local YAdjust = .1

        while true do
    	    clone.PrimaryPart.CFrame = clone.PrimaryPart.CFrame + Vector3.new(0, YAdjust, 0)
    	    Y = clone.PrimaryPart.Position.Y
    	    if math.abs(initialY - Y) >= 1 then
    		    YAdjust *= -1
    	    end
      	    task.wait()
        end
    end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.