I am trying to make a model hover in place a little bit by using SetPrimaryPartCFrame. I tried using for loops and while loops in order to make it go up the proper amount and down the same amount but I quickly realized that it would glitch out since it would execute both loops at the same time. I tried to do this as a fix since I wasn't sure how to check if the position of the part's CFrame was returned to its original spot:
local model = script.Parent
local up = true
while true do
if up == true then
for i = 1,2, .1 do
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, 0 + i, 0))
wait()
print(i)
end
up = false
end
if up == false then
for i = 2, 1, -.1 do
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0, 0 - i, 0))
wait()
print(i)
end
up = true
end
end
I used the variable up as a way to check if its moving up or not and it seemed to work for a little while but after a few seconds one of the loops began to take over and the object slowly kept going lower and lower towards the ground rather than going up and down the same amount to give a hovering effect. I was just wondering if there is an easier fix for this.
Thanks in advanced, any help is appreciated.

2 comments
It already does that...?
Not quite, the model moves lower and lower after a couple of seconds of running the script.