Killing a player at the end of the timer

Good day to all! I want to make a script that will kill the player regardless of where he is when the timer expires. This is my example, the script kills the player only when he is on the baseplate

local timeremaing = 10


while timeremaing > 0 do
	print("Seconds remaining:" .. timeremaing);
	wait(1)
	timeremaing = timeremaing - 1	
end
if timeremaing == 0 then 
	script.Parent.Touched:Connect(function(hit) 
	if hit.Parent:FindFirstChild("Humanoid")then 
        hit.Parent.Humanoid.Health = 0 
	    end 
		end)

end
3 Likes

Are you trying to kill a specific player or all the players when the timer expires?

1 Like

Im trying to kill a specific player

You’ll have to create some sort of system for whatever you’re trying to do to get a specific player through certain conditions and then kill them. Here’s an example

local timeremaing = 10

local plrs = game.Players:GetPlayers()

local randomplr = plrs[math.random(1,#plrs)] --Gets a random player

while timeremaing > 0 do
	print("Seconds remaining:" .. timeremaing);
	wait(1)
	timeremaing = timeremaing - 1	
end
if timeremaing == 0 then 
	local char = randomplr.Character
	if char then --If they are alive when timer runs out since if char is nil, the character was not loaded when the time ended
		local hum = char:WaitForChild("Humanoid")
		hum.Health = 0 
	end
end

I’m disappointed with all these responses

local Players = game:GetService("Players")

Players.PlayerAdded:Wait() -- optional

for i = 20, 0, -1 do
	print("Time remaining:", i)
	wait(1)
end

local player = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]

local human = player.Character and player.Character:WaitForChild("Humanoid")
human:TakeDamage(100)
1 Like
for second = 10, 0, -1 do
    print("Time Remaining: " .. second)
    wait(1)
end

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == "Blah" then -- Player you want to kill
        hit.Parent:FindFirstChild("Humanoid"):TakeDamage(100) -- Amount of Damage
    end
end)
1 Like