I’m having an issue in getting the speed of a player’s torso for a speedometer. It’s detecting the player’s torso but it stops running once It gets to the Changed
part (noted below) as I’ve figured out in debugging.
GUI Hierarchy
The LocalScript is disabled by default until the UI is cloned and placed into the player’s PlayerGui.
I apologize if it’s unclear, I tried to explain it as best as I could.
--SPEEDOMETER
function getSpeed(part)
if part.Velocity == Vector3.new() then
return 0
else
local dot = part.CFrame.lookVector:Dot(part.Velocity.unit)
return (dot*part.Velocity).magnitude*(dot<0 and -1 or 1)
end
end
--END SPEEDOMETER
--LP = game.Players:WaitForChild("LocalPlayer")
script.Parent.F.B.Delete.Activated:Connect(function()
game.ReplicatedStorage.Vehicles.DeleteTrain:FireServer()
end)
if game.Players.LocalPlayer.Character:FindFirstChild("Torso") then
print("Torso")
game.Players.LocalPlayer.Character.Torso.Changed:Connect(function() -- <- HERE
print("ok")
local spe = getSpeed(game.Players.LocalPlayer.Character.Torso)
print(spe)
script.Parent.F.Speed.Text = tostring(spe)
end)
elseif game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso") then
game.Players.LocalPlayer.Character.UpperTorso.Changed:Connect(function()
local spe = getSpeed(game.Players.LocalPlayer.Character.UpperTorso)
script.Parent.F.Speed.Text = tostring(spe)
end)
end