How do i detect object position in a loop(while)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I wanna achieve when object position is 0,2,0 it’s go back like 0,0,0

  2. What is the issue? Include screenshots / videos if possible!
    I have no idea how i add that in loop

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to use vector3 value, but idk how to add it to there

local SpinObject = script.Parent
while SpinObject.Position <= SpinObject.Position == Vector3.new(0,2.537,0)  do
	SpinObject.Position += Vector3.new (0,1,0)
	task.wait(1)
end
1 Like

Still have no idea how to do that lol help pls

1 Like

you can do this:

local SpinObject = script.Parent

SpinObject:GetPropertyChangedSignal("Position"):Connect(function()
	if SpinObject.Position.Y >= 2 then
		SpinObject.Position += Vector3.new(0,-SpinObject.Position.Y,0)
	end
end)
1 Like

hmph uhh
Bruh when i made it <= it just dissapeared from workspace

1 Like

I just need it get + 2 position and then - 2 position and loop that

1 Like

wth image

1 Like

Try using the magnitude with the two vectors to detect the difference in an if statement.

Something like this:

local SpinObject = script.Parent
while SpinObject.Position.Magnitude == Vector3.new(0,2.537,0).Magnitude  do
	SpinObject.Position += Vector3.new (0,1,0)
	task.wait(1)
end
1 Like
while true do SpinObject.Position = SpinObject.Position + Vector3.new (0,2,0)
	task.wait(1)
SpinObject.Position = SpinObject.Position - Vector3.new (0,2,0)
task.wait(1)
end

??

Oh this could be because i made that

local SpinObject = script.Parent
SpinObject:GetPropertyChangedSignal("Position"):Connect(function()
	if SpinObject.Position.Y <= 2 then
	SpinObject.Position += Vector3.new (0,1,0)
	task.wait(1)
	end
end)

SpinObject:GetPropertyChangedSignal("Position"):Connect(function()
	if SpinObject.Position.Y >= 2 then
		SpinObject.Position -= Vector3.new (0,1,0)
		task.wait(1)
	end
end)

Thanks that work, good work =D

Okay nvm, i got a problem, i can just make it go up, but can’t make it go down