Hi!
So I’m trying to make a rangefinder which tell’s you the distance of what you are pointing at but while I was testing the code, It gave me this error which I am finding hard to fix and thought of asking smarter people on how to go about fixing it…
Here’s my code.
local character = player.Character
local textLabel = script.Parent
local function updateDistance()
local distance = (character.HumanoidRootPart.Position - textLabel.Position).Magnitude
textLabel.Text = "Distance: " .. tostring(distance)
end
local userInputService = game:GetService("UserInputService")
local function onKeyPressed(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Z then
updateDistance()
end
end
userInputService.InputBegan:Connect(onKeyPressed)
--The above code is placed inside a localscript in a textlabel btw