Kicking players

I want to kick players but it doesn’t work.

if humanoid.Health == 0 or humanoid.Health < 0 then
	for index, player in pairs(game.Players:GetPlayers()) do -- go thru every single player
		player:Kick("e") -- kick the player
	end -- end the for loop
end

This is my script. Even if my humanoid rig get’s to zero or below zero I do not get kicked from the game.

How it’s put in the workspace.

Summary

Currently the code you’ve supplied will only run one time. You’ll need to place it in a loop or just check when the player dies and kick them.

Here is an example:

while true do
   if humanoid.Health == 0 or humanoid.Health < 0 then
        for index, player in pairs(game.Players:GetPlayers()) do 
		player:Kick("e") -- kick the player
	    end 
   end
end

-- or

humanoid.Died:Connect(function()
for index, player in pairs(game.Players:GetPlayers()) do
		player:Kick("e") -- kick the player
	end 
end)

Just like what @Prince_Duke was saying, you’re only running the code once. Try wrapping it inside a :GetPropertyChangedSignal() event

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	if humanoid.Health == 0 or humanoid.Health < 0 then
		for index, player in pairs(game.Players:GetPlayers()) do -- go thru every single player
			player:Kick("e") -- kick the player
		end -- end the for loop
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.