How do i make object position go higher by 2 and after that go lower by 2(but not teleport, moves)

  1. What do you want to achieve? Keep it simple and clear!
    Title

  2. What is the issue? Include screenshots / videos if possible!
    My script don’t works so idk what to do

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed add some variables, but this didn’t help

local SpinObject = script.Parent
local x = 0
while x == 0  do
	SpinObject.Position += Vector3.new (0,0.1,0)
	task.wait(0.05)

	if SpinObject.Position == Vector3.new(-166.06, 2.929, 245.986) then
		x = 1
		end
		
	
	end
while x == 1  do
	SpinObject.Position -= Vector3.new (0,0.1,0)
	task.wait(0.05)
	if SpinObject.Position == Vector3.new(-166.06, 0.929, 245.986) then
		x = 0
	end
	end

bruuuuuh i still have even no idea how to make that works, help pleaase

We can’t help you if you haven’t tried debugging it or telling us what’s wrong with the script.

Bruh i explained everything lmao, it’s just don’t works, i need it just go higher by 2 and lower by 2 z position

It’s just go up very much not by 2

Have you tried debugging the script to see what’s wrong? Devforum isn’t about giving all the answers, its a step by step solution to them.

You can also use TweenService | Roblox Creator Documentation for this.

image

local SpinObject = script.Parent
local x = 0
while x == 0  do
	print("first loop works good")
	SpinObject.Position += Vector3.new (0,0.1,0)
	task.wait(0.05)

	if SpinObject.Position == Vector3.new(-166.06, 2.929, 245.986) then
		x = 1
		end
		
	
	end
while x == 1  do
	print("second loop works good")
	SpinObject.Position -= Vector3.new (0,0.1,0)
	task.wait(0.05)
	if SpinObject.Position == Vector3.new(-166.06, 0.929, 245.986) then
		x = 0
	end
	end

x is still 0 i think or it’s don’t detect when x value changes

If you want it to up you just have to change the y value and keep everything at 0.

No i mean it must be like when z coordinate is 2 z cordinate lowers by 0.01 each 0.05 seconds to z coordinate 0

You should use tweenservice or lerp for that.

hmmmm can you exactly explain how to do that?

I’ve already sent the tweenservice link with it. Lerp is basically like tweenservice, but for cframes.

erm lol image

Is the part anchored? I also can’t help you if you don’t show me the code. :slight_smile:

Ofc anchored

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

local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

local tween = TweenService:Create(SpinObject, tweenInfo, {Position = Vector3.new(0, 2, 0)})

tween:Play()

Alr using ts (30 lettersssssssssssss)

Try un-anchoring it, play around with the part.

It’s doing strange things, now it’s spins and doing same thing as before

I think this is because of easing direction, what exactly directions are there?