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

Script not kicking players when required?

I am trying to make this script kick the players once the timer reaches 0, however I have had no luck in trying to get this to work so far this is the code I have

timer = game.ReplicatedStorage:WaitForChild("Timer")
timer.Value = 5


while true do 
	if timer.Value >= 1 then
	timer.Value = timer.Value - 1
	wait(1)
	else return nil 
	end
	
	end
	

-- everyone below not working

function update()
	local p = game.Players:GetPlayers()
	if timer.Value == 0 then
	for i = 1, #p do 
	p[i]:Kick()
	end
	end
end

while wait(.33) do 
	update()
end



Also should I be using a remote function/event when kicking clients?

1 answer

✓ Accepted answer

This should work:

local kickreason = "Timer ran out."--Reason for being kicked
local Timer = 5--The timer value--How long before the players get kicked
for i=Timer,0,-1 do--For every second do this
Wait(1)--Wait a second
end
for i, player in pairs(game.Players:GetPlayers()) do--For every player do
player:Kick(kickreason)--Kick all players
end

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