Best way to unstun someone after the tool disappears

I’m currently working on a punch system, but I’ve run into a problem. When the player is stunned, and the person who stuns them dies… they don’t unstun.

I know that the cause is because when the tool is destroyed, the script that’s meant to unstun them is also destroyed. I’m kind of lost on what to do, as the tool is deleted after a person dies.

function onTouched(hit)
	if hit:IsA("BasePart") and hit.Name == "Torso" or hit:IsA("BasePart") and hit.Name == "UpperTorso" or hit:IsA("BasePart") and hit.Name == "LowerTorso" or hit:IsA("BasePart") and hit.Name == "HumanoidRootPart" then
		if script.Parent.Transparency == 0 then
			local human = hit.Parent:FindFirstChild("Humanoid");local Attacker = script.Parent.Parent.Parent:FindFirstChild("Humanoid")
			if hit.Parent ~= nil and human.Parent:GetAttribute("Ragdoll") == false and Attacker.Health > 0 then
				warn(Attacker.Parent.Name)
				script.Parent.Transparency = 0.8;human.Parent:SetAttribute("Ragdoll",true)
				spawn(function()
					task.delay(math.random(4,6),function()
						if human and human.Parent ~= nil then
							human.Parent:SetAttribute("Ragdoll",false)
						end
					end)
				end)
				task.delay(8,function()
					script.Parent.Transparency = 0
				end)
			end 
		end
	end
end

if (script.Parent ~= nil) and (script.Parent.className == "Part") then
	connection = script.Parent.Touched:Connect(onTouched)
end
1 Like

use .Destroying event on the tool and cancel any stuns

1 Like

This doesn’t work on a script inside of the tool though… does it?

it does
It will fire the function right before the tool gets deleted

2 Likes


As @Verdancyx said, it will fire as your tool is destroying itself.

function onDestroy()
     --cancel current stuns
end

script.Parent.Destroying:Connect(function()
     onDestroy()
end)
1 Like

@MikeartsRBLX & @Im_aLEGOperson456

I have tried this, and it never prints anything. I’ve created a mega thread regarding the whole systems issues to see if anyone can help… if you’d be willing to help, please check that out.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.