Scope doesn't work properly for clients in Multiplayer

(ENTIRE CODE PASTBIN AT THE BOTTOM)

Hello,

Currently I have a SWEP that includes a scope with X-RAY capabilities, in Singleplayer and as the server host, the scope works just as intended with no problems.

However, my friend (who is a client on the server with considerably high latency) reports that when Unzooming from the scope, the overlay and X-RAY effect will linger for up to 5 seconds before going away.

I am assuming this very much has to do with lag and such but I haven’t the slightest on how to resolve it.

Am I close by assuming this has to do with Prediction?

If anybody could show me what’s going on, I would very much appreciate it.

Thank you for your time.

Here is the relevant code to the scope.

How it is triggered.
image

Scope Function.
image

X-RAY Function

Viewmodel and Sensitivity.
image

and the overlay

ALSO: The X-Ray function is called inside of SWEP:Think()

If you want to look at the entire code, here’s that too:

For anyone who comes across this with the same issue, I figured out the solution to the issue I was having.

It seemed that setting the status of the weapon being zoomed in as a NWBool caused this.

What I did was change that to a NetworkVar called “IsZoomedIn” created inside of SWEP:SetupDataTables()
And then setting the bool to true / false respectively when using the scope.

I am not 100% sure why this fixed the issue but there ya go.

Hope this helps someone.