Shop opening for all online players

Hello. When a person talks to one of the NPCs on the server, they will say a message, which will also be printed into the chat with correct formatting (e.g Merchant: Hello, how can I help you?) and after a few seconds a shop will open up.
This is the code I have to do this:
init.lua


        if ( tr.Hit and tr.HitNonWorld and tr.Entity:GetClass() == "npc_monk" ) then
		
			umsg.Start("ShopNPCUsed", ply)
			umsg.End()
			
			timer.Simple( 3, function(ply)
			umsg.Start("MerchantShop", ply)
			umsg.End()
			end, ply)

cl_init.lua


local ply = LocalPlayer()
local function NPCShopMenu(ply)

	surface.PlaySound( "vo/coast/odessa/nlo_cub_hello.wav" )
	chat.AddText(Color(255,255,128), "Merchant: ",Color(255,255,255), "Ah! Hello. I'll be right with you." )
	
end
usermessage.Hook("ShopNPCUsed", NPCShopMenu)

cl_merchantshop.lua



usermessage.Hook("MerchantShop", merchantstoremenu)


The problem is: the sound that is played, the text that is printed into the chatbox, and the shop are seen for all players. I want it to only work for the person who talked to the NPC in the first place.

Any help is GREATLY appreciated.

Could you post the whole init.lua function?

Sounds like “ply” is nil in init.lua, posting a larger snippet of the scope or the entire function would be helpful.


 

function GM:KeyPress( ply, key )
 
	if (ply:OnGround( ) and key == IN_WALK ) then
	
	if (Walking == false) then
        ply:SetWalkSpeed(100)
		Walking = true
		ply:SendLua("GAMEMODE:AddNotify(\"Walking mode enabled.\", NOTIFY_GENERIC, 2)")
	elseif (Walking == true) then
        ply:SetWalkSpeed(200)
		Walking = false
		ply:SendLua("GAMEMODE:AddNotify(\"Walking mode disabled.\", NOTIFY_GENERIC, 2)")
    end
	
	end
 
    if (ply:OnGround( ) and key == IN_USE ) then
	
        local tr  = util.QuickTrace( ply:EyePos( ), ply:GetAimVector( ) * 128, ply )
		
        if ( tr.Hit and tr.HitNonWorld and tr.Entity:GetClass() == "npc_monk" ) then
		
			umsg.Start("ShopNPCUsed", ply)
			umsg.End()
			
			timer.Simple( 3, function(ply)
			umsg.Start("MerchantShop", ply)
			umsg.End()
			end, ply)
			
		elseif ( tr.Hit and tr.HitNonWorld and tr.Entity:GetClass() == "npc_eli" ) then
				
			umsg.Start("ShopNPCUsed2", ply)
			umsg.End()
			
			timer.Simple( 3, function(ply)
			umsg.Start("MerchantShop2", ply)
			umsg.End()
			end, ply)
			
		end
	end
end


UPDATE: Fixed the bug using my own initiative. Thanks everyone for your input. The code above stays in case anyone is in need of it.