Changing a metatable's functions seems to stack overflow and not work

Hi, at the moment I’m trying to create a function so when you call SetModel on a player it calls SetModel on an entity with the same arguments, while ignoring the SetModel called on the player. I asked around somewhat, and got some code from a friend. It is as follows:



d=ents.Create("dummy")
d:SetPos(Vector(0,0,100))
d:Spawn()
d:Activate()

plr=player.GetHumans()[1]
Obj=d
getmetatable(Obj).SetModel = (function (Str)
plr:SetModel(Str)
end)
Obj:SetModel("models/headcrab.mdl")


(the Dummy entity is just a regular entity with no special code attached, sort of like prop_physics)
Now what I think this should do is when I call Obj:SetModel on the last line, it should set the player’s model to a headcrab. However all I get is the following error

[lua\autorun\server\fakemodel.lua:9] stack overflow

Any reasons or fixes for this? I’d much appreciate the help.

[lua]local d = ents.Create(“dummy”)
d:SetPos(Vector(0,0,100))
d:Spawn()
d:Activate()

local p = player.GetHumans()[1]

local oldModel = d.SetModel
function d:SetModel(str)
p:SetModel(str)
return oldmodel(self,str)
end[/lua]

Not tabbed seen as I wrote it in the reply box.

For some reason this completely refuses to work when I call it with


timer.Create("test",1,1,function()
d:SetModel("models/headcrabclassic.mdl")
end)

…at the end of the script. It simply changes entity “d”'s model instead of the player’s.
(I wonder why it won’t let me use lua tags?)