Hi!
I have a working distance script, but I need to make it detect when the player is moving in the air and on the ground. My code is below:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local part1 = Character:WaitForChild("HumanoidRootPart")
local part2 = game.Workspace:FindFirstChild("KSAN1")
local txt = part2.BillboardGui.txtDistance
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Humanoid.MoveDirection.Magnitude <= 0 then return end
local distance = (part1.Position - part2.Position).Magnitude
txt.Text = ("%.2f"):format((distance/20000)).."km"
end)
The script works when a player is walking, but it does not work when they are, say, flying an aircraft. This is a big problem since my game is an aviation game, so I need the script to update when the player is moving not only in 2D but in 3D as well. Any help is appreciated!
Thanks in advance.