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

How do I make this timer kill the player?

Okay so I am making a WarioWare on roblox. So what I need is to make this timer script kill the player when it ends. But how do I do that?

SCRIPT:

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

Let me explain: WarioWare has a bunch of minigames alright. So I am remaking it in roblox. In WarioWare there is a 4 second timer for every minigame when it ends you lose. Thats what I'm doing for this understand?

2 answers

✓ Accepted answer

You want to use the Humanoid:TakeDamage(number) function:

local seconds = script.Parent.Parent.Time

local oldValue = seconds.Value -- we want the initial value so we know when the time is up

script.Parent.Text = seconds.Value

for i = 1,seconds.Value do
	
	wait(1)
	seconds.Value -= 1
	script.Parent.Text = seconds.Value 
	
	if i == oldValue then
		
		game.Players.LocalPlayer.Character.Humanoid:TakeDamage(100) -- 100 is the default max health for roblox characters
		
	end
	
end

However, this script will run only one time, after it kills the player one time, it will not run again. So if you want it to keep killing the player after the time is up, use this script:

local seconds = script.Parent.Parent.Time

local oldValue = seconds.Value -- our target value

local count = 0 -- to keep track of our count

while wait(1) do
	
	seconds.Value -= 1
	script.Parent.Text = seconds.Value
	count += 1 -- getting the count up
	
	if count == oldValue then -- if the count is our target value
		
		game.Players.LocalPlayer.Character.Humanoid:TakeDamage(100) -- 100 is the default max health for roblox characters
		count = 0 -- resetting the count
		
	end
	
end

Hope this helped!

1 comment

0

Tysm!!!

Alright, this is pretty messy. Let me fix it up for you

local seconds = script.Parent.Parent.Time.Value --you need to define the value of time or its just an object

script.Parent.Text = seconds

are you trying to make an infinite loop? looks like it.

for i  = 1,100 do --for for loops you use 2 values it can count up to
       script.Parent.Text = seconds - 1
       wait(1)
end

for loops aren't infinite, and you need to organize your loop and give it an end. when it ends you can kill the player, but I need to know which player. reply to it in the comments here's the full product:

local seconds = script.Parent.Parent.Time.Value
seconds.value = 100 --you need to set the value of where it counts down from
script.Parent.Text = seconds

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

3 comments

0

This answer is very wrong. First, you're setting "seconds" to the ONLY the value, it DOES NOT lead to the actual property. Then, you're doing "seconds.value = 100", though you had already set it to value, and you also didn't capitalize the "v". And he is also asking on how to kill the player, and I don't see anything related to that in your answer.

0

I probably should've explained better. I don't need the value I have a NumberValue that holds the value of the time. I also don't want it to be infinite.

0

Not infinite looped lol. Btw this didn't help me at all

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