Damage function problem

I want to figure out why every time a player resets they are unhittable.

I’ve tried looking for the problem but I don’t understand what I did wrong.

When you join the game and a players is already there before you then you’d be able to hit them and they can’t hit you but when they reset they can hit you but you can’t hit them.

local HitPlayers = {}
	
	
	
	local function Damage()
		print("Damage Function")
		for i = 1,#HitPlayers do

		if HitPlayers[i] == Client.Character then return end
		if HitPlayers[i] == nil then return end
		
		
		if HitPlayers[i].Humanoid.Health > 0 then
		
		HitPlayers[i].Humanoid:TakeDamage(5)
		if HitPlayers[i].Humanoid.Health <= 0 then Client.leaderstats.Kos.Value = Client.leaderstats.Kos.Value + 1 end
		
		local PunchedSound = HitPlayers[i].HumanoidRootPart.Punched
		PunchedSound:Play()
		
		local Particle = ReplicatedStorage:WaitForChild("Particles").Hit:Clone()
		Particle.Parent = HitPlayers[i].HumanoidRootPart.ParticleAttachment
		Particle.Enabled = true
		Debris:AddItem(Particle,0.1)
		
		if CombatType == 4 then
				Module:Ragdoll(HitPlayers[i],1)
				local bv = Instance.new("BodyVelocity",HitPlayers[i].Torso)
				bv.P = math.huge
				bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				bv.Velocity = Client.Character.HumanoidRootPart.CFrame.lookVector * Vector3.new(15,15,15)
				Debris:AddItem(bv,0.3)
			end
		local Stun = Instance.new("StringValue",HitPlayers[i].Status)
			Stun.Name = "stun"
			local StunAnimation = HitPlayers[i].Humanoid:LoadAnimation(Animations[TablePosition.."Stun"])
			StunAnimation:Play()
			HitPlayers[i].Humanoid.WalkSpeed = 0
			wait(0.2)
			Stun:Destroy()
			HitPlayers[i].Humanoid.WalkSpeed = 16
			

				table.remove(HitPlayers,i)
				print("Fixed")
			end
		end
	end

There is a for i,v in pairs loop that I did not include it puts the parents on the nearest torso inside of the table.

Are you using SpawnLocations and a non-zero value for Duration? (which create a forcefield for characters that (re)spawn)

Is this damage on the client? You can’t damage other players from your client.

I fixed it the function is in a server script which is fired by a remote event.

Okay, then mark me as a solution.