New to lua, Predicted hook

Hi, i am pretty new to lua and i am trying to create a little addons for fun. The problem i have is for some reason the function seems to repeat itself 2 to 3 times. I dont really understand predicted hooks and i was wondering if anyone could help. Here is the code i have done so far

function HolsterToBack( ply, oldWeapon, newWeapon )
 ply:ChatPrint( "You switched weapons! Your old weapon is " .. oldWeapon:GetClass() .."." )
 ply:ChatPrint( "Your new weapon is " .. newWeapon:GetClass() .. "." );

hook.Add("PlayerSwitchWeapon","HookHolsterToBack", HolsterToBack)

Thanks for helping me and have a good day.

Sorry for my bad english.

Predicted hooks are hooks that run in the client and in the server.
They mostly run in the client to help with predictions and to try and make the little lag someone has less noticeable.
It doesn’t run like 2 times each time, its just runs 1 on the client and 1 on the server if im not mistaken.

[editline]2nd August 2016[/editline]

Oh, wait and in weapons in the client it actually gets called two times, one in the predicted moment and the other one when the client receives the info so you can do other things you need to in the client.
To check if its predicted or not use this function:


Actually, both realms can get run multiple times depending on the situation. One thing to note is that predicted hooks don’t run clientside in single-player except Think.

Think is not predicted.

Think is predicted properly in multiplayer, but garry added a hack to make it call clientside in singleplayer which is why ply:GetCurrentCommand() fucks up in that case.