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

How to Kick All Players Using a Script?

I have seen some answers to this question, but it isn't working for me at the moment. I wanted to kick all players in the server (up to 6) when the value inside a NumberValue hit 0 or lower. The NumberValue is named Health and is located in

game.Workspace.Wall

Anyone have any pointers?

3 answers

✓ Accepted answer

Player has a method called Kick for kicking the player off the server, with an optional parameter for what message to show them. The NumberValue class, as well as some of the other ones such as StringValue, also have an event that fires for whenever the value is changed called Changed. Given this information, all that needs to be done is check if the value is less than or equal to 0 in a function connected to the Changed event, and then call the kick method on every player if it is.

local Players = game:GetService("Players")
game.Workspace.Wall.NumberValue.Changed:Connect(function(value)
	if value <= 0 then
		local players = Players:GetPlayers()
		for i, player in ipairs(players) do
			player:Kick("get out")
		end
	end
end)

Put this script anywhere on the server:

game.Workspace.Wall.Health.Changed:connect(function(value)
	if value <= 0 then
		for i,Player in pairs(game.Players:GetChildren()) do
			Player:Kick("Lol bye")
		end
	end
end)

2 comments

0

"connect" has been depreciated. Use "Connect" instead.

0

is depreciated*

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