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.
local dummy = script.Parent local dummy2 = dummy:clone() log = game.ReplicatedStorage.Tool local humanoid = dummy:WaitForChild("Humanoid") humanoid.Died:connect(function() --Regen wait(5) dummy:Destroy() dummy2.Parent = workspace dummy2:MakeJoints() for i=1,3 do local clonedTool = log:Clone() clonedTool.Parent = workspace clonedTool.Position = dummy.Torso.Position end 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.
local humanoid = dummy:WaitForChild("Humanoid") humanoid.Died:connect(function() end) --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 :)
local dummy = script.Parent local dummy2 = dummy:clone() local log = game.ReplicatedStorage.Tool local clonedTool = log:Clone() local humanoid = dummy:WaitForChild("Humanoid") humanoid.Died:connect(function() --Regen clonedTool.Parent = workspace clonedTool.Handle.Position = dummy.Torso.Position wait(5) dummy:Destroy() dummy2.Parent = workspace dummy2:MakeJoints() if clonedTool.Parent == workspace then clonedTool:Destroy() end end)