So, say I have two entities on the ground, and I want to target one only with Player:GetEyeTrace(), is there a way to target only the entity the player is looking at and not both entities? Sorry, I am new to lua and if this has already been covered then I am sincerely sorry.
A trace can only hit one thing, so the trace result’s .Entity field will be the one they are looking at.
what = pl:GetEyeTrace( ).Entity if IsValid( what ) then --Do something end
Oh wow I feel stupid, thanks. x.x
Sorry if this is considered double posting, but am I supposed to put the expected entity into “what”? I want to assume I am but I really don’t want to run into some lua error. For example if I were to:
npc_alyx = pl:GetEyeTrace.Entity if IsValid( npc_alyx ) then RunConsoleCommand("kill") end
Not my intentions for use, just an example.
GetEyeTrace should have brackets. It should look like