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?
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!
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