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

? I need help with timer that will kick after 80 seconds. I dont have much time left!

3 answers

I wish I didn't misunderstand you, here is a code I made and labeled everything so you can know it works.

The code:

local part = script.Parent -- Makes "part" aim to the parent of the script(Part).

local function touched(hit) -- Runs when the parent of the script(Part) is touched, "hit" is the "Object" that touched the Part.
	local partParent = hit.Parent -- Gets the parent of the "hit"
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") -- Checks if the "hit" is a humanoid(Player).
	if humanoid then -- If it is a humanoid then do the code bellow.
		part:Destroy() -- Do not remove this! this deletes the part after it's touched so it wont spam the touch function.
		local countdown = 80 -- Starts a count down from 80 to 1.
		while countdown > 1 do -- Checks if it ended.
			wait(1) -- Waits 1 s before removing one number.
			countdown = countdown - 1 -- Removes one number.
			print(countdown) -- Prints the new number.
		end -- Ends the countdown.
		for index, player in pairs(game.Players:GetPlayers()) do -- Goes thru every single player.
			print("Countdown done, kicking.") -- Prints a message into the "output"
			player:Kick("You lost") -- Kicks the player and the message.
		end -- Ends the loop.
	end -- Ends the if.
end -- Ends the function.

part.Touched:Connect(touched) -- Function.

I wish I helped !

local function kickAll(Time,KickMessage)
	wait(Time)
	for i, v in pairs(game.Players:GetPlayers()) do
		v:Kick(KickMessage)
	end
end

First, you'll need to check if the wall is touched.

Wall.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		-- We'll put our code here
	end
end)

GetPlayerFromCharacter will get the player from a character's model, if it exists. This is to check if an actual player touched the wall. Next, we need to start the timer. You could use task.wait(80), which will simply wait 80 seconds, but if you want an actual timer:

local Timer = 80 -- Define a variable, which will store the current time
for t = 0, 80 do -- A simple loop, which will run from 0 to 80, with t being the current value
	Timer -= 1
end

And at the end, we'll need to kick all of the players.

Timer -= 1
if Timer == 0 then
	for _, Player in pairs(game.Players:GetChildren()) do
		Player:Kick()
	end
end

pairs() returns an iterator, which can be looped through using for index, value in pairs(). It's used to loop through dictionaries.

And here's the full code:

Wall.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local Timer = 80
		for t = 0, 80 do
			Timer -= 1
			if Timer == 0 then
				for _, Player in pairs(game.Players:GetChildren()) do
					Player:Kick()
				end
			end
		end
	end
end)

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