Taser SWEP

Hi

I’ve made a taser swep, it works great aslong as there’s only one player tased on the map at one time.
I belive this is because the “pos” variable changes to the latest tased player:


rag:SetPos( ply:GetPos() )

then in the tase revive function:


ply:SetPos(rag:GetPos())

If I tase player 1 he will fall asleep where he stands, if I then tase player 2, player 1 will spawn at player 2s rag:GetPos().
I assume this is because the ply is the latest ply that got tased, so the position doesn’t get the unique plys position, but the latest one.

I’ve removed code that isn’t necessary to show here:


function SWEP:tasePlayer(ply, shooter)
	local eyetrace = self.Owner:GetEyeTrace();
	pos = ply:GetPos()
	-- create ragdoll
	 rag = ents.Create( "prop_ragdoll" )
    if not rag:IsValid() then return end
	-- build rag
	rag:SetModel( ply:GetModel() )
    rag:SetPos( ply:GetPos() )
	rag:SetAngles(ply:GetAngles())
    rag:Spawn()
    rag:Activate()

	timer.Simple(10, function() revive(ply, rag, WeaponsForSleep) end) 
end



-- revive player from being a ragdoll
function revive(ply, rag, WeaponsForSleep)
	local health = ply:Health()
	ply:Spawn()
	ply:SetHealth(health)
	ply:SetPos(rag:GetPos())
end

So I wonder, how do I make it so it’s the unique players position, and not the latest player?

Make the variables local?

Wow, I have to go back to LUA school.
Thank you very much.