What I want: I want a dummy that, when I kill it, it drops 3 tools that I can pick up. After 5 seconds, if the tools are not picked up, I want them to be deleted. I also want the dummy to regen after 5 seconds.
What I get: When I kill the dummy, it does not drop anything, it only regens after 5 seconds.
01 | local dummy = script.Parent |
02 | local dummy 2 = dummy:clone() |
03 | log = game.ReplicatedStorage.Tool |
04 |
05 |
06 | local humanoid = dummy:WaitForChild( "Humanoid" ) |
07 |
08 | humanoid.Died:connect( function () --Regen |
09 | wait( 5 ) |
10 | dummy:Destroy() |
11 | dummy 2. Parent = workspace |
12 | dummy 2 :MakeJoints() |
13 |
14 | for i = 1 , 3 do |
15 | local clonedTool = log:Clone() |
16 | clonedTool.Parent = workspace |
17 | clonedTool.Position = dummy.Torso.Position |
18 | end |
19 | end ) |
When using if statements in this context, you run the risk that the conditions won't pass. If the conditions don't pass, it means that the events inside of the if statements will never get connected.
You know that the Humanoid will exist, the only question is whether it exists now. Therefore, you can safely use WaitForChild
to delay the script until it exists.
1 | local humanoid = dummy:WaitForChild( "Humanoid" ) |
2 |
3 | humanoid.Died:connect( function () |
4 | end ) |
5 |
6 | --etc. |
working script below, except for the 3 item clones. i couldnt get it to work so i took it out but the cloning works.
good luck :)
01 | local dummy = script.Parent |
02 | local dummy 2 = dummy:clone() |
03 | local log = game.ReplicatedStorage.Tool |
04 | local clonedTool = log:Clone() |
05 |
06 | local humanoid = dummy:WaitForChild( "Humanoid" ) |
07 |
08 | humanoid.Died:connect( function () --Regen |
09 |
10 |
11 |
12 | clonedTool.Parent = workspace |
13 | clonedTool.Handle.Position = dummy.Torso.Position |
14 | wait( 5 ) |
15 | dummy:Destroy() |