Speed value not working properly

Hello.
I am trying to make a speedometer for my plane, and want to create a value that will be updated constantly with the current speed relative to the ground. Here is my current code:

local Velocity = MainPlane.Nose.Velocity.Magnitude 

while Enginevalue == 1 do
	Velocity = MainPlane.Nose.Velocity.Magnitude
	SpeedUI.SpeedTextIndicatorGUI.Text = ('Speed ' ..Velocity.. ' knots')
	task.wait()
end

When the plane is spawned in, the value is at zero, however when I start moving, the value remains at zero instead of changing.

Thank you in advance.

2 Likes

try changing the

while Enginevalue == 1 do

to

while true do

and see first if it works

1 Like

Engine value is needed here, as I need it to be active when it is equal to one. I also tried the while true do script separately, however that did not work either.

1 Like

Perhaps this’ll work?

local Velocity = MainPlane.Nose.AssemblyLinearVelocity.Magnitude 

while Enginevalue == 1 do
	Velocity = MainPlane.Nose.AssemblyLinearVelocity.Magnitude
	SpeedUI.SpeedTextIndicatorGUI.Text = "Speed " .. Velocity .. " Knots"
	task.wait(.01)
end
1 Like

Tried this as well, but it did not work. I did find the solution myself just now by combining the entire script with the enginevalue function. Neither the less, thank you for your help, very much appreciate it.

1 Like

how about this:

local mainplane = game.Workspace:WaitForChild("MainPlane",10)
local Velocity = 0
local EngineValue = 1
local nose

if mainplane ~= nil then
	nose = mainplane:WaitForChild("Nose",8)
	if nose ~= nil then
		while EngineValue == 1 do	
			Velocity = nose.Velocity.Magnitude
			SpeedUI.SpeedTextIndicatorGUI.Text = ('Speed ' ..Velocity.. ' knots')
			task.wait(.1)
		end
	end
end

I tried something similar with no issues. Place both scripts in startercharacter:
localscript 1 makes the nose part:

print("Nose Generator!")
local char:Model = script.Parent
local nose = Instance.new("Part")
nose.Color = Color3.new(0, 1, 0)
nose.Size = Vector3.new(5,5,5)
nose.Anchored = false
nose.CanTouch = false
nose.CanCollide = true
nose.CFrame = CFrame.new(0,8,-16)
nose.CustomPhysicalProperties = PhysicalProperties.new(2,.3,1)
nose.Name = "Nose"
task.wait(2)
nose.Parent = game.Workspace

Localscript 2 displays the speed:

local char:Model = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local SpeedUI = player.PlayerGui:WaitForChild("SpeedUI",10)
local Velocity = 0
SpeedUI.SpeedTextIndicatorGUI.Text = ('Speed ' ..Velocity.. ' knots')
local nose = workspace:WaitForChild("Nose",8)

for x = 2, 0, -1 do
	warn("Countdown = ".. tostring(x))
	task.wait(1)
	
end
warn("Drop!")
nose:PivotTo(CFrame.new(0,300,-16))


while true do
	Velocity = nose.Velocity.Magnitude
	SpeedUI.SpeedTextIndicatorGUI.Text = ('Speed ' ..Velocity.. ' knots')	
	task.wait(.1)
end