I am making a speedometer and I am having some issues when using the magnitude value in arithmetic calculations.
When I try and divide the magnitude value I get the error:
This is the script so far:
local RunService = game:GetService('RunService')
local Players = game:GetService('Players')
local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local leaderstats = player:WaitForChild("leaderstats")
local topSpeed = leaderstats:WaitForChild("Top Speed")
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local speedometerGui = script.Parent
local pin = speedometerGui:WaitForChild("pin")
local function onHeartbeat()
local speed = HumanoidRootPart.Velocity.magnitude
local percentOfMax = math.floor((speed/topSpeed) * 100)
print(percentOfMax.."%")
end
RunService.Heartbeat:Connect(onHeartbeat)
Any help would be greatly appreciated!