Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Any better way to use the while true do loop?

Asked by 7 years ago

So I'm trying to make a floating boat simple alright. But I think while true do loop is going to lag the place up with lots of them. So I'm looking for a simpler/cleaner way to do this opinions?

I've tryed do a function but it didn't work what am I doing wrong?

seat:FindFirstChild('SeatWeld'):connect(function()
end)
local seat = script.Parent
local loc = script.Parent.Parent
local base = loc:WaitForChild('Base')
local bodygyro = base:WaitForChild('BodyGyro')
local bodyvelocity = base:WaitForChild('BodyVelocity')
local bodyposition = base:WaitForChild('BodyPosition')
bodyposition.Position = base.Position -- adjusting :P
base.BodyGyro.CFrame = base.CFrame
value1 = 7

while true do
wait()
local speed = seat.MaxSpeed
local turnspeed = seat.TurnSpeed
if seat.Throttle== 1 then
if value1 < speed then value1 = value1+1 end
bodyvelocity.Velocity = base.CFrame.lookVector*value1
end
if seat.Throttle == 0 then
value1 = 0
bodyvelocity.Velocity = base.CFrame.lookVector*value1
end
if seat.Throttle== -1 then
if value1<14 then value1 = value1+1 end
bodyvelocity.Velocity = base.CFrame.lookVector*-value1
end
if seat.Steer == 1 then
bodygyro.CFrame = bodygyro.CFrame * CFrame.fromEulerAnglesXYZ(0,-(turnspeed),0)
end
if seat.Steer == -1 then
bodygyro.CFrame = bodygyro.CFrame * CFrame.fromEulerAnglesXYZ(0,turnspeed,0)
end
end
0
while wait() do end -- This just prevents you from having to put wait() after the true statement. Also, you could check less often like using a wait(1) and that will 100% reduce lag. AstrealDev 728 — 7y

Answer this question