Help with plane system

So I made a plane system similar to jailbreaks where the plane flies and lands on the runway. I wrote the spawning part so the plane spawns and then flies to the runway and lands. The problem is, that the plane instantly stops when it hits the landing node.
This is unrealistic since in real life it takes planes a few seconds for them to come to a halt. So I decided to gradually tween the speed down. I came across a problem. I’ve spent 30 minutes trying to fix this!

When I tween the speed, instead of slowing down, the plane just stops, when it should be taking 5 seconds for it to slow down!

Script:

local TweenService = game:GetService('TweenService')

local PlaneController = {}
PlaneController.__index = PlaneController

function PlaneController.new(planeModel,nodes)
	assert(typeof(planeModel) == 'Instance')
	assert(typeof(nodes) == 'Instance')
	
	local self = setmetatable({},PlaneController)
	
	self.Nodes = nodes
	self.PlaneModel = planeModel
	self.Node = 0
	self.Speed = 50
	
	return self
end

function PlaneController:TweenSpeed(num,speed)
	local value = Instance.new('IntValue')
	
	value:GetPropertyChangedSignal('Value'):Connect(function()
		print('Changed value to '..value.Value)
		self.Speed = value.Value
	end)
	
	local info = TweenInfo.new(
		num,
		Enum.EasingStyle.Quart,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	local tween = TweenService:Create(value,info,{Value = speed})
	
	tween:Play()
	tween.Completed:Wait()
	print('Tween finished')
end

function PlaneController:Spawn()
	print('Ran')
	self.Plane = self.PlaneModel:Clone()
	
	-- welding
	
	local descendants = self.Plane:GetDescendants()
	
	for i = 1,#descendants do
		if descendants[i] ~= self.Plane.PrimaryPart and descendants[i]:IsA('BasePart') then
			local weld = Instance.new('Weld')
			weld.Name = 'PlaneWeld'
			weld.Part0 = self.Plane.PrimaryPart
			weld.Part1 = descendants[i]
			weld.C0 = self.Plane.PrimaryPart.CFrame:inverse()
			weld.C1 = descendants[i].CFrame:inverse()
			weld.Parent = self.Plane.PrimaryPart
		end
	end
	self.Plane.Parent = workspace.CargoPlane
	
	self.Plane:SetPrimaryPartCFrame(self.Nodes.Node1:GetPrimaryPartCFrame())
	
	wait()
	
	self:Fly()
end

function PlaneController:Fly()
	self.Node = self.Node + 1
	
	local node = self.Nodes:FindFirstChild('Node'..self.Node)
	
	if not node then
		if self.Node ~= 8 then
			self:DespawnPlane()
			return
		end
	end
	
	if self.Node == 8 then
		wait(8)
		warn('Complete')
		self:Fly()
	end
	
	if self.Node == 7 then
		self:TweenSpeed(5,0)
	end
	
	local distance = (self.Plane.PrimaryPart.CFrame.p - node:GetPrimaryPartCFrame().p).Magnitude
	
	local Time = self:GetTime(distance)
	
	local tweenInfo = TweenInfo.new(
		Time,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	
	local PlaneTween = TweenService:Create(self.Plane.PrimaryPart,tweenInfo,{CFrame = node:GetPrimaryPartCFrame()})
	PlaneTween:Play()
	
	wait(Time)
	
	self:Fly()
	
end

function PlaneController:GetTime(distance)
	return distance / self.Speed
end

function PlaneController:DespawnPlane()
	self.Node = 0
	self.Plane:Destroy()
	self.Plane = nil
end

return PlaneController

Here is where I call the TweenSpeed function:

	if self.Node == 7 then
		self:TweenSpeed(5,0)
	end

I feel as if there is a simple fix, but I just cannot find it! :joy:

Thanks! :smile:

2 Likes

I am but I’m tweening it (and the duration is 5 seconds) so it should stop slowly yet it stops instantly.

2 Likes

I noticed you have a print statement that prints the speed when it changes. Does that print go from 50-0 or does it go straight to 0?

I was just going to mention, that it doesn’t print at all!

I would bet that the self:TweenSpeed function never plays. Right below the following code could you add a print statement like print(self.Node) to see if the self.Node makes it to 7.

It does run, because when I added a print it prints.

Just to let everyone know, the :GetPropertyChangedSignal() doesn’t fire.

1 Like

Maybe you can’t tween an int value, because int values have to have integers and tweens usually go into decimals. Maybe do a for loop that changes the speed and waits (0.1)?

Before I was using a number value and I switched to an int value incase that was the problem which it wasn’t.

From what i can see, you are never putting a parent to the IntValue, it is stored in nil, i could be wrong but that is my theory.

you can always try making the plane into an animatable rig and using animations to move the plane rather than tweenservice to get more realistic and clean movement thats much easier to control what happens to it

That’s way over the top. My plane has 1000s of parts and I feel like that’s just too much.

ah yeah fair enough, with that amount of parts it would probably lag just trying to make the animations lol

Even when I used a for i = 1 loop it still instantly goes to the speed.

The speed variable your inputting is 0 I’m not sure if that’s the cause but that’s all I could point out.
And if I were you change the IntValue to a number value to support decimals.