Not very experienced with CFrame and Parts, so I'll explain anyway, basically I want to check to see if something isn't at a certain Y value and if it is not it will change, here's what I mean:
function CheckYValue() while wait() do if Part.CFrame.Y ~= 458.4 then -- I think this is the problem.. Part.CFrame = Part.CFrame * CFrame.new(0, 0, 0.1) -- I can do this bit! else return end end
It is likely that Part.CFrame.Y
doesn't become exactly 458.4
. Many times when manipulating Vector3s or CFrames there can be rounding errors (very close numbers to what they should be, like 458.400002
).
This kind of bug can usually be fixed by rounding the number and then comparing it.
function CheckYValue() while wait() do if math.floor(Part.CFrame.Y*10 + 0.5)/10 ~= 458.4 then -- rounding to the nearest 0.1 Part.CFrame = Part.CFrame * CFrame.new(0, 0, 0.1) else return end end end
Another way is to check if the difference between the two is very small.
function CheckYValue() while wait() do if math.abs(Part.CFrame.Y-458.4) > 0.01 then -- greater than 0.01 between the two Part.CFrame = Part.CFrame * CFrame.new(0, 0, 0.1) else return end end end