Confusion as to why script doesn't work

Hello! I was wondering why this script of mine isn’t working. As you can see, the game should wait 5 seconds before kicking every player. Then, the kicked players are provided the message “lol.” I am running this as a regular script in the workspace. I’ve tried moving some stuff around, running it as some stuff. I’m a bit stuck.

local Players = game:GetService("Players")
while true do
    Players:Kick("lol")
    end 

Players doesn’t have a Kick method, only the players inside of the Players service do

1 Like

You’re trying to kick the players service, you need to get all the players via GetPlayers, loop through and kick those players

local Players = game:GetService("Players")

while true do
	wait(5)
	for _, player in pairs(Players:GetPlayers()) do
		player:Kick("lol")
	end	
end 

Also you had no wait

2 Likes

It’s an iterator function that can go through tables and dictionaries. For this case, GetPlayers returns a table of the players in game, pairs goes through the table and returns 2 things, the index of the current iteration and the value stored at that index, basically it’s just another type of loop

1 Like