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

This script is meant to kick everyone if the counter reaches zero?

local seconds = script.Parent.Parent.Time

script.Parent.Text = seconds.Value

for i = 1,seconds.Value do
	
 wait(1)
 seconds.Value = seconds.Value - 1
 script.Parent.Text = seconds.Value
end

if seconds <= 0 then
local players = game.Workspace.Player:GetPlayers()
	players:kick()
	end


I don't understand why it's not kicking me?

3 comments

0

game.Workspace.Player:GetPlayers() ? dont you mean game.Players:GetPlayers() and the loop though the array to kick each player

0

Time is an int value correct?

0

Time is a numberValue

4 answers

try on line 13

for i,v in pairs(game.Players:GetChildren()) do
v:kick()
end

1 comment

0

It still did not work

local Time = (script.Parent.Parent.Time);
script.Parent.Text = (Seconds.Value);

for i = 0,tonumber(Seconds.Value) do
	wait(1)
	Seconds.Value = Seconds.Value - 1
	script.Parent.Text = Seconds.Value
end

if Seconds.Value <= 0 then
	for i,v in pairs(game.Players:GetPlayers()) do
		v:Kick("The timer has reached zero!")
	end
end

1 comment

0

I have changed some of the variables letters case-wise, so you can change that if it's not identifiable by the script. This should work.

Here, this should work.

The reason I believe your script isn't working is because it's not constantly checking if seconds.Value is equal to 0. Therefore it won't kick the players'. Here it's in a while loop so it's constantly checking if the value is equal to 0, if it is then it will kick all players.

local Players = game:GetService("Players")
local seconds = script.Parent.Parent.Time

while wait(1) do
	
	script.Parent.Text = seconds.Value

	seconds.Value = seconds.Value - 1
	
	if seconds.Value <= 0 then
		for i,v in pairs(Players:GetChildren()) do
			v:Kick()
		end
	end
end

1 comment

0

this is correct, he has to move the if statement into the loop.

Use an in pairs loop to loop through the players and kick each value, like this :

local PlayersService = game:GetService("Players")
local PlayerServiceChildren = PlayersService:GetChildren()

for i, v in pairs(PlayerServiceChildren) do
	v:Kick()
end

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