I'm lost when it comes to traces...

Hi there, I’ve been trying to create a crappy Metal Gear-esque gamemode, and production has gone along fine… Until I came upon the issue of getting the alert working when a guard sees Snake.

I know I have to use a trace, and I’ve tried scouring the Gmod Wiki mirrors (other trace related searches only bring up clientside aimbots), but I’m still somewhat confused. I believe I have to use this to conduct the trace, but then I have no idea what to do from there.

[lua]function sight()
if traceRes.HitNonWorld then
sight = true
sight = false


This is my coding for this part so far. As you can see, pretty lackluster. I need to make it so that sight only equals true if the guard see’s Snake, who is on the opposite team (while ignoring the guard’s teammates) but I haven’t seen anything which discriminates based on team. Plus to add onto that, I need to make it so Snake can’t use it, which makes it all the more worrying. Can anyone help me? It would be extremely appreciated!

function Alert()

for k, v in pairs(player.GetAll()) do
	if v:Team() == GUARD_TEAMNUMBER_HERE then
		local tr = v:GetEyeTrace()
		if tr.Entity:GetClass() == "player" and tr.Entity:Team() == SNAKE_TEAMNUMBER_HERE then
			-- do whatever you want for alert


hook.Add(“Think”, “Alert”, Alert)
Untested code. Tell me if it errors, or if you want it commented.

Thank you VERY much for the response! As soon as I get a test ready, I’ll report back with the results!