Per player ply variable?

Hello, I have been doing other things for about a year, but I am now getting back into Lua, and am confused about this; here is my code.


local varPCopied = 0
local ply
AddStickTool("Move Entity", { -- This currently only works as one player on the clipboard at a time for the whole server
	Description = "Moves an entity.",
	Icon = "icon16/group_go.png",
	CanTarget = anything,
	OnRun = function(Player, Trace)
		 if varPCopied == 1 then
            if not IsValid(ply) then varPCopied = 0 return end
			local pos = Trace.HitPos
--			Stick_SendChat(Player, "test")
			ply:SetPos(pos)
			Stick_SendChat(Player, "Pasted.")
			varPCopied = 0
		else
			if not (Trace.Entity == Entity(0)) then -- Moving the world crashes the game, no need to do that
				ply = Trace.Entity
				varPCopied = 1
				Stick_SendChat(Player, "Copied.")
			end
		end
	end
})

What this does, is if you swing a stick at an entity (players included) it will copy it, then when you swing it somewhere else on the map, it will teleport the entity to that location.

The problem with this is that if there is multiple people using this tool at the same time, the “clipboard” will get messed up, and the wrong entity can be moved.

How do I alter this so that the tool is per player? Thanks.

You can make any variable player-specific by changing ‘varname = …’ into ‘ply.varname = …’
This is true for all Entities

Player.ply works for copying the entity, but it won’t paste.

Edit: Nevermind, I forgot to change one of them, thanks, it works now.