Adding a hook to the SetModel function?

Hello, I’ve tried this to add a hook to the SetModel function of players, but it throws me an error.

CODE:




local plymeta = FindMetaTable( "Player" )
if not plymeta then return end

local setmodel= plymeta.SetModel

function plymeta:SetModel(model)
	setmodel(self, model)
	hook.Run( "OnPlayerChangedModel", self, model )
end


ERROR:



[ERROR] lua/autorun/server/sizes_color.lua:29: attempt to call upvalue 'setmodel' (a nil value)


Any help would be appreciated

Wrong section. Can this be deleted or moved please?

SetModel is in the entity metatable, not the player.

Thank you for that!