I’m making a rangefinder tool which works at first, but after I get in a vehicle seat that runs some camera code and then try and use it again it gives me a really low number for distance.
local Players = game:GetService("Players")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local equipped = false
local UIS = game:GetService("UserInputService")
function round(n)
return math.floor(n * 10) / 10
end
script.Parent.Equipped:Connect(function()
UIS.MouseIconEnabled = false
equipped = true
player.CameraMode = Enum.CameraMode.LockFirstPerson
workspace.CurrentCamera.FieldOfView = 25
local PlayerGUI = game.Players.LocalPlayer.PlayerGui
local Clone = tool.RangeGUI:Clone()
Clone.Parent = PlayerGUI
local TextLabel = Clone.Compass.Text
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("MeshPart") then
v.Transparency = 1
end
end
mouse.Button1Down:Connect(function()
mouse.TargetFilter = script.Parent
if equipped == true then
print(player.Character.HumanoidRootPart.Position)
wait(.1)
local magnitude = math.abs((player.Character.HumanoidRootPart.Position - mouse.Hit.Position).Magnitude)
wait(0.1)
print(mouse.Hit.Position)
game.Players.LocalPlayer.PlayerGui.RangeGUI.Compass.Text = round(magnitude) --.." How many degrees up "..a
end
end)
end)
script.Parent.Unequipped:Connect(function()
equipped = false
UIS.MouseIconEnabled = true
player.CameraMode = Enum.CameraMode.Classic
workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
game.Players.LocalPlayer.PlayerGui.RangeGUI:Destroy()
workspace.CurrentCamera.FieldOfView = 70
end)
game["Run Service"].RenderStepped:Connect(function()
if equipped == true then
game.Players.LocalPlayer.PlayerGui.RangeGUI.TextLabel.Text = math.floor(player.Character.HumanoidRootPart.Orientation.Y)
else
end
end)