'UniqueID' (a nil value)

Error:


[ERROR] lua/autorun/server/ghostdeath.lua:8: attempt to call method 'UniqueID' (a nil value)
           1. fn - lua/autorun/server/ghostdeath.lua:8
            2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
             3. TakeDamageInfo - [C]:-1
              4. DealDamage - lua/weapons/weapon_fists.lua:140
               5. unknown - lua/weapons/weapon_fists.lua:99

Line 8:


	if ( GhostDeath.Ghosts[ply:UniqueID()] ) then return false end



GhostDeath = GhostDeath or {}
GhostDeath.Ghosts = GhostDeath.Ghosts or {}
GhostDeath.DeadTime = GhostDeath.DeadTime or 60 -- Here the time in second that players will be waitting before respawn.

function GhostDeath.Block( ply )

	if ( GhostDeath.Ghosts[ply:UniqueID()] ) then return false end

end

local IsAliveOld = debug.getregistry()["Player"]["Alive"]

function IsAlive( ply )

	if ( GhostDeath.Ghosts[ply:UniqueID()] ) then
		return false
	end

	return IsAliveOld( ply )
end

debug.getregistry()["Player"]["Alive"] = IsAlive



function GhostDeath.PlayerDeath( ply, inflictor, killer )

	local opos = ply:GetPos()
	local omod = ply:GetModel()
	
	local pRag = ents.Create( "prop_ragdoll" )
	pRag:SetModel( omod )
	pRag:SetPos(ply:GetPos())
	pRag:SetOwner( ply )
	pRag:Spawn()
	pRag:GetPhysicsObject():SetVelocity(ply:GetVelocity())
	pRag:SetCollisionGroup( COLLISION_GROUP_WEAPON )

	ply:StripWeapons()
	ply:UnSpectate()
	ply:UnLock()
	ply:Spawn()
	ply:StripWeapons()

	if ( ply:GetRagdollEntity() and IsValid( ply:GetRagdollEntity() ) ) then
		ply:GetRagdollEntity():Remove()
	end

	timer.Simple(0.1, function()
		ply:SetModel(omod)
		ply:StripWeapons()
		ply:SetNoDraw( true )
		ply:SetMoveType( MOVETYPE_WALK )
		ply:SetGravity(0)
		ply:GodEnable()
	
		ply:SetCustomCollisionCheck( true )
		ply:SetPos(opos)

	end)
	

	GhostDeath.Ghosts[ply:UniqueID()] = ply

	
	umsg.Start("ghostdeath_death")
		umsg.Entity( ply )
		umsg.Bool(true)
	umsg.End()

	timer.Create("GhostDeath_" .. ply:UniqueID(), GhostDeath.DeadTime, 1, function()

		if ( pRag and IsValid( pRag ) ) then
			pRag:Remove()
		end

		if ( !ply or !IsValid(ply) ) then return end
		
		if ( timer.Exists( "GhostDeath_" .. ply:UniqueID() ) ) then
	
			timer.Destroy( "GhostDeath_" .. ply:UniqueID() )
		
		end

		umsg.Start("ghostdeath_death")
			umsg.Entity( ply )
			umsg.Bool(false)
		umsg.End()

		GhostDeath.Ghosts[ply:UniqueID()] = nil
		
		ply:SetCustomCollisionCheck( false )
		ply:GodDisable()
		ply:SetNoDraw( false )
		ply:SetMoveType( MOVETYPE_WALK )
		ply:SetGravity( 0 )
		ply:Spawn()
		ply:SendLua([[LocalPlayer():EmitSound("items/ammo_pickup.wav", 100, 100)]])
		

	end)

end

function GhostDeath.PlayerInitialSpawn( ply )

	if ( timer.Exists( "GhostDeath_" .. ply:UniqueID() ) ) then
	
		timer.Destroy( "GhostDeath_" .. ply:UniqueID() )
		
		timer.Simple(5, function()
		
			ply:ChatPrint( "You can't exploit the system, my friend." )
			ply:Kill()
		end)

	end

end

function GhostDeath.ShouldCollide( ent1, ent2 )


	if ( ent1.IsPlayer and GhostDeath.Ghosts[ent1:IsPlayer()] and ent2 and IsValid(ent2) ) then

		return false

	end
	
	if ( ent2.IsNPC and GhostDeath.Ghosts[ent2:IsNPC()] and ent1 and IsValid(ent1) ) then
	
		return false
		
	end

end

function GhostDeath.SetupMove(ply, mv)

	if ( not GhostDeath.Ghosts[ply:UniqueID()] ) then return end

	if ( ply:KeyDown(IN_JUMP) ) then
		mv:SetVelocity( ply:GetAimVector() * 300 )
	end

end



hook.Add( "ShouldCollide", "GhostDeath.ShouldCollide", GhostDeath.ShouldCollide )
hook.Add( "PlayerInitialSpawn", "GhostDeath.PlayerInitialSpawn", GhostDeath.PlayerInitialSpawn )
hook.Add( "SetupMove", "GhostDeath.SetupMove", GhostDeath.SetupMove )

hook.Add( "PlayerDeath", "GhostDeath.PlayerDeath", GhostDeath.PlayerDeath )
hook.Add( "PlayerSpawnObject", "GhostDeath.PlayerSpawnObject", GhostDeath.Block )
hook.Add( "PlayerSpawnRagdoll", "GhostDeath.PlayerSpawnRagdoll", GhostDeath.Block )
hook.Add( "PlayerSpawnProp", "GhostDeath.PlayerSpawnProp", GhostDeath.Block )
hook.Add( "PlayerSpawnEffect", "GhostDeath.PlayerSpawnEffect", GhostDeath.Block )
hook.Add( "PlayerSpawnNPC", "GhostDeath.PlayerSpawnNPC", GhostDeath.Block )
hook.Add( "PlayerSpawnSENT", "GhostDeath.PlayerSpawnSENT", GhostDeath.Block )
hook.Add( "PlayerSpawnSWEP", "GhostDeath.PlayerSpawnSWEP", GhostDeath.Block )
hook.Add( "PlayerSpawnVehicle", "GhostDeath.PlayerSpawnVehicle", GhostDeath.Block )
hook.Add( "PlayerDeathThink", "GhostDeath.PlayerDeathThink", GhostDeath.Block )
hook.Add( "PlayerSay", "GhostDeath.PlayerSay", function( p )

	if ( GhostDeath.Ghosts[p:UniqueID()] ) then
		return ""
	end


end)

hook.Add( "PlayerCanHearPlayersVoice", "GhostDeath.PlayerCanHearPlayersVoice", function( _, talker )

	if ( GhostDeath.Ghosts[talker:UniqueID()] ) then
		return false, false
	end

end)

hook.Add( "GetFallDamage", "GhostDeath.GetFallDamage", GhostDeath.Block )
hook.Add( "ScalePlayerDamage", "GhostDeath.ScalePlayerDamage", GhostDeath.Block )
hook.Add( "EntityTakeDamage", "GhostDeath.EntityTakeDamage", GhostDeath.Block )
hook.Add( "ContextMenuOpen", "GhostDeath.OnContextMenuOpen", GhostDeath.Block )
hook.Add( "PlayerSwitchFlashlight", "GhostDeath.PlayerSwitchFlashlight", GhostDeath.Block )
hook.Add( "CanPlayerSuicide", "GhostDeath.CanPlayerSuicide", GhostDeath.Block )

hook.Add("Think", "fuckyoudarkrp", function()

	hook.Remove( "PlayerSpawn", "AntiMapKill")
end)

//hook.Add( "EntityTakeDamage", "GhostDeath.EntityTakeDamage", GhostDeath.Block )

I need help fixing this.

The player isn’t valid.

So how would I go about fixing it?

Who is GhostDeath.Ghosts? You have to use player.UniqueID with a valid player.