Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make a script that allows me to kill every player in a game?

i need a piece of code that allows me to get all the players inside the games humanoids and set all there health's to 0, if you help thank you! if you don't, thanks for reading

2 answers

First of all, this is NOT a request site!

This site is meant for you to try making the code yourself and then asking questions if you're unsure about what you did.

I'll give you a code anyways, because it's a simple code:

local Player_List = game.Players:GetPlayers() --This returns a table that contains every player in the game
for _, Plyr in pairs(Player_List) do --This is a "special" for loop that is used to iterate through tables
	if Plyr and Plyr.Character then --This checks to see if the player has a character
		local Humanoid = Plyr.Character:FindFirstChild("Humanoid") --This checks to see if the Plyr has a Humanoid. If it does, it returns the Humanoid. If it doesn't, it returns nil
		if Humanoid then --If the Plyr has a Humanoid
			Humanoid.Health = 0 --Kill the Plyr
		end
	end
end

Well this site isn't exactly for requests but I'll help you anyways since it's fairly simple. Read the green parts too, you might learn something!

players = game.Players:GetChildren()
--[[ 
	Gets all of the things 
	that are in a "folder" 
	called players. (You can
	see it in your explorer in
	studio!) and puts them all 
	into a variable (Like algebra!) 
	called players!
--]]

for k,v in pairs(players) do
	--[[
		For every single player in 
		the players variable, make 
		variable k be their position 
		in the variable players, and v 
		be the actual player in the game!
	--]]
	
	if v.Character then --If the player has a character then do the next line!
		v.Character.Humanoid.Health = 0 --Set the player's character's humanoid's health to 0!
	end --This tells the game that your if then statement is over!
	wait() --Tells the game to wait a very short amount of time to kill the next player, this helps stop lag!
end --This one tells the game your for do statement is over!

Look on the roblox wiki for clickdetectors and functions to trigger this script! Have fun!

This discussion is preserved as it was. New answers, comments, and votes are closed.