So I've been trying to make a part that Goes from starting position to the end position when another part is touched then connected it to a function and a for loop inside it to increase the the Y axis by .5, then I did an if statement to check if its reached its maximum position, and if it didn't it would execute the event touched then connect it to the function to make it go up, but the if statement didn't work.. Here's my script:
MovedPart = script.Parent
MoverScript = MovedPart.Mover
TouchEqualMove = workspace.TouchE
debounce = false
MaxPos = workspace.MaxPosOfMovedPart
StartingPos = workspace.StartingPosOfMovedPart
h = 0
function Ontouched(part)
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(part.Parent) then
print(part.Name)
for i = .5, 10.5, .5 do
h = h + .5
MovedPart.Position = Vector3.new(40, h, -22)
print (MovedPart.Position)
wait(.5)
end
end
wait(2)
debounce = false
end
end
if MovedPart.Position == MaxPos.Position then
print("Max position reached!")
elseif MovedPart.Position == StartingPos.Position then
TouchEqualMove.Touched:connect(Ontouched)
end
The problem is that the if statement isn't checking if MovedPart.Position == MaxPos.Position but executing the elseif statement which is already done, so when i touch it again (where MaxPos is (40, 10.5, -22) it goes up in Y axis like so: (40, 21, -22) and so on on the Y-axis Is there something wrong with the If statement?

2 comments
try 'if MovedPart.Position == Vector3.new(MaxPos.Position) then'
Didn't work either :/