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