Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make this timer kill the player?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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!

0
Tysm!!! Koley_Moley -7 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

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
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. User#32819 0 — 4y
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. Koley_Moley -7 — 4y
0
Not infinite looped lol. Btw this didn't help me at all Koley_Moley -7 — 4y

Answer this question