I'm trying to create a function that returns a part

I wanted to make a moving platform that goes and returns when it reaches a specific position. The ReturnPart function doesn’t seem to work, it didn’t make the part return, the part just keeps going. What did I do wrong?

a while loop repeats infinitely, so your part will go down forever and the code below it will never run

Position is a property not a function so you cant put parenthesis. you should do something like this:

if RevolingTrail.Position == Vector3.new(9,25,-25) then -- Vector3.new(x,y,z) represents a position

end

heres how you should move a part and then move it back

function movePartAndBack()
  part.Position += Vector3.new(0,0,-2)
  task.wait(1) -- 1 second. task.wait() is a more precise version of wait()
  part.Position += Vector3.new(0,0,2)
end

movePartAndBack()
1 Like

Try this code. The main problem RevolingTrail.Position() is not a thing, use RevolingTrail.Position = Vector3.new(X, Y, Z) instead. Other than that, I just made a few minor adjustments, so it should work as you wish.

local RevolvingTrail = script.Parent
local ZPosition = RevolvingTrail.Position.Z

local Number = -2

function ReturnPart(String)
	if String == "Positive" then
		Number = 2
	else
		Number = -2
	end
end

RevolvingTrail:GetPropertyChangedSignal("Position"):Connect(function()
	if RevolvingTrail.Position.Z <= -255.498 then
		ReturnPart("Positive")
	elseif RevolvingTrail.Position.Z >= ZPosition then
		ReturnPart("Negitave")
	end
end)

while true do
	task.wait(0.01)
	RevolvingTrail.Position += Vector3.new(0, 0, Number)
	task.wait(0.01)
end
1 Like

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