Need help with kill script

My game has a shop that has some power ups in it. One of the power ups is the instant kill script. Which lasts the entire length of my game. I have a localscript controlling the shop and a serverscript carrying out the kills.

Localscript:

ShopGUI.kill.Buy.Activated:Connect(function()
	game.ReplicatedStorage.KillHumanoid:FireServer() 
end)

Serverscript:

ReplicatedStorage.KillHumanoid.OnServerEvent:Connect(function(player)
	while wait(0.5) do
		workspace[player.Name].Killpart.Touched:Connect(function(hit)
			if debounce then return end
			debounce = true
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if humanoid ~= nil then
				local victim = game.Players[humanoid.Parent.Name]
				if humanoid ~= player.Character.Humanoid and victim.Team ~= game.Players[player.Name].Team then
        			humanoid.Health = 0
       				humanoid.Died:Connect(function()
						if isDead then return end
						isDead = true
						game.Players[player.Name].leaderstats.Kills.Value += 1
						isDead = false
					end)
					wait(0.5)
    			end
				debounce = false
			end
		end)
	end
end)

The issue is with the server script I think. When I buy the power up. For the first time, I am able to kill my friend. My friend dies and then respawns. Everything is well. After he respawns, he comes at me and I can’t seem to kill him a second time. This is the problem because I want the power up to last the whole game, not just one time. I have a while wait(0.5) do loop just so I can check if I am touching another player every half a second. I have no idea why this is the case and it seems to happen everytime .

Put a wait() at the end of your loop to see if it fixes the problem.

Isn’t that accomplished with the while wait(0.5) do?

No, that starts the loop. You need to end it otherwise I don’t think it will work the way you want it to.

So do I add it here:

while wait(0.5) do
   --other code
   wait() 
end

Yeah, but a 1 inside it. (30 ch)

What does this accomplish for the code?

To make it work so it doesn’t work just once.

i believed the problem is with your debounce

you set the debounce = false inside if humanoid ~= nil but set it to true outside it. so that when it set to true but humanoid is nil, it never go back to false and therefore your code not working anymore, it only loop to the if debounce then return end

So where should I set the debounce relative to the code?

You need to make sure debounce is set to false at the end and have the wait.

It should be after the end of if humanoid ~= nil block