My while loop is preventing my velocity function for my car from working

im trying to make my car float up and down with a tween continuously without it tampering with my other functions. do you guys have any recommendations to clean this up? i have the velocity and tweens function in the same script.

		local function floating_tweens()
			return coroutine.create(function()
				while zalek_data.car_isfloating.Value == true do
					local currentCF = zalek:GetPivot()
					local floatdown_CF = currentCF * CFrame.new(0, -5, 0)
					local tinfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true, 0)
					zalek_data.floatTween = ts:Create(zalek.PrimaryPart, tinfo, {CFrame = floatdown_CF})
					zalek_data.floatTween:Play()
					zalek_data.floatTween.Completed:Wait()
					
					if zalek_data.car_isfloating.Value == false then
						break
					end
					task.wait()
				end
			end)
		end
1 Like

Instead ease a number which you will then add to the velocity
you could also just use math.sin(tick())

then you just do :
velocity += Vector3.new(0, offsetY, 0)
(just an example, i dont know how yours is set up)

making offsetY negative will move the car down and the opposite is also true

2 Likes

i found out a better way of doing my function, so far it works so dats coo’

		local function floating_tweens()
			local currentCF = zalek:GetPivot()
			local floatdown_CF = currentCF * CFrame.new(0, -5, 0)
			local tinfo = TweenInfo.new(2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true, 0)
			zalek_data.floatTween = ts:Create(zalek.PrimaryPart, tinfo, {CFrame = floatdown_CF})
			zalek_data.floatTween:Play()
		end

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