Player resetting bug

Hi guys :slightly_smiling_face:, I’ve encountered this bug while trying to make a function which stuns another player if a player says no to a decision shown on their ui. For some reason, sometimes it just seems to reset the other player for no apparent reason. I don’t know if this is a ragdoll issue or my code. Will be sending both sources;


function StunHolder(Character: (Model))
	Character:SetAttribute('Ragdoll', true)
	Character:SetAttribute('Busy', true)

	for _,v in Character:GetChildren() do
		if v:IsA('BasePart') then
			if v.Name == 'HumanoidRootPart' then continue end
			local Stun = script.FX.Stun:Clone()
			Stun.Parent = v
			Stun.Enabled = true
		end
	end
	
	local SFX = script.Sounds.Electric:Clone()
	SFX.Parent = Character.PrimaryPart
	SFX:play()
	
	task.delay(5, function()
		if Character:IsDescendantOf(workspace) then
			for _,v in Character:GetChildren() do
				if v:IsA('BasePart') and v:FindFirstChild('Stun')then
					v:FindFirstChild('Stun').Enabled = false
					task.delay(.5, function()
						SFX:Destroy()
						v:FindFirstChild('Stun'):Destroy()
					end)
				end
			end

			task.delay(1, function()
				Character:SetAttribute('Ragdoll', false)
				Character:SetAttribute('Busy', false)
				
			end)
		end
	end)
	
end

And my ragdoll module is from: [Updated] Perfect R6 Ragdoll - Easiest Ragdoll System for R6 Avatars

I’m slightly sure it’s from the ragdoll… not sure though. If anyone has a good R6 ragdoll module I could use, please let me know :slight_smile: Thanks!