Hello, i’m having some problems with finding distance between entities, i’m a real lua noobie.
Let’s say I have a couch and a table and I want to check if they are close enough, it’ll print a message “The couch and the table are close( less then 100 units )”
I found this code online, but im not sure how I can get it to work…
function DistanceInformation(entity) for k,v in pairs(ents.GetAll()) do if v:GetClass() == "couch" && v:GetPos():Distance(entity:GetPos()) < 100 then print("its less than 100 units away") else print("its more than 100 units away") end end end
I put the code into one of the entities init.lua file and called a timer on it(I need to check if both entities are close to each other every 1 sec).
And my console just get spammed by “its more than 100 units away” (not by the timer), and then this error comes up:
Attempt to call method GetPos (a nil value), I understand there’s a problem, I cant find it though :\