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

How to add a timer so the player holding the object will die?

Asked by 6 years ago

Hey guys, So, I'm fairly new to LUA scripting and would love some help.

So basically, I want to add a timer, and when the timer runs out the person with the object last, dies. Kind of like time bomb.

As I said, I'm really new to this, so I'd love a helping hand. :-)

0
Lua, not LUA. User#24403 69 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

There are events for Tool.Equipped:Connect()

You can start a timer in the script then access the player's humanoid and set the health below or equal to zero. Remember to also use Tool.Unequipped:Connect() or disconnect the event.

Ad
Log in to vote
0
Answered by 6 years ago

Put this inside the tool instance itself (not the part, the tool) as a normal script (not a local or module)

01local tool = script.Parent
02local currentime = 0 -- Current Time (once it equals timend, it will make the player with it die)
03local timend = 5 -- Time max (in seconds)
04 
05function toolEquipped()
06    begin()
07end
08 
09tool.Equipped:connect(toolEquipped)
10local db = 0
11function begin()
12if db == 0 then
13db = 1
14 
15function getHumanoid()
View all 42 lines...

This script however will not make anything die if it's not equipped by a player.

But I did make it so it will only do the counting only IF equipped by a humanoid/player.

Answer this question