Ragdoll kills the Player

Hello everyone,
I’ve made a weapon into my game, that ragdolls people. The first hits are kind of working, it ragdolls and unragdolls, but doesn’t apply any force to the player’s humanoid. After a few hits it “kills” that player, just player ragdolls and their hats/hair will go through the floor and will never stand up, after 2 to 5 seconds player kills themselves and the player will respawn.
Snímka obrazovky 2024-07-31 222238
Snímka obrazovky 2024-07-31 222329
Sometimes player will just be ragdolled forever, they can’t move nor reset. Just reconnect.
Snímka obrazovky 2024-07-31 222300

Here’s script to that weapon:

local Player
repeat
	wait()
	Player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
until Player

local character : Model = Player.Character
local humanoid : Humanoid = character:WaitForChild("Humanoid")
local rygtip = humanoid.RigType
local animationTrack : AnimationTrack
if rygtip == Enum.HumanoidRigType.R15 then
	animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(script:WaitForChild("15"))
else
	animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(script:WaitForChild("6"))
end
local debounce = false
local hitpart : Part = script.Parent:WaitForChild("hitpart")
local sound : Sound = hitpart:WaitForChild("Bonk!")

local function ragdoll(char : Model)
	for _, joint in ipairs(char:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint", joint.Parent)
			local attachment0 = Instance.new("Attachment", joint.Part0)
			local attachment1 = Instance.new("Attachment", joint.Part1)

			attachment0.CFrame = joint.C0
			attachment1.CFrame = joint.C1

			socket.Attachment0 = attachment0
			socket.Attachment1 = attachment1
			socket.TwistLimitsEnabled = true
			socket.LimitsEnabled = true

			joint.Enabled = false
		end
	end
end

local function unragdoll(char)
	for _, joint in ipairs(char:GetDescendants()) do
		if joint:IsA("Motor6D") then
			joint.Enabled = true
		elseif joint:IsA("BallSocketConstraint") then
			joint:Destroy()
		end
	end
end

script.Parent.Activated:Connect(function()
	if debounce then return end
	debounce = true
	animationTrack:Play()

	local connection
	local char : Model
	local charHumanoid : Humanoid
	local RagdollValue : BoolValue
	connection = hitpart.Touched:Connect(function(hit)
		char = hit.Parent
		if not char:FindFirstChild("Humanoid") then
			char = hit.Parent.Parent
			if not char:FindFirstChild("Humanoid") then
				char = nil
				charHumanoid = nil
				return
			end
		end

		if not char:FindFirstChild("RagdollValue") then
			RagdollValue = Instance.new("BoolValue")
			RagdollValue.Value = false
			RagdollValue.Parent = char
			RagdollValue.Name = "RagdollValue"
		else
			RagdollValue = char:FindFirstChild("RagdollValue")
		end
		sound:Play()

		if RagdollValue.Value then return end
		RagdollValue.Value = true
		RagdollValue:SetAttribute("Hitter", Player.UserId)

		charHumanoid = char:WaitForChild("Humanoid")
		charHumanoid.Sit = false
		charHumanoid:ChangeState(Enum.HumanoidStateType.Physics)
		charHumanoid.WalkSpeed = 0
		charHumanoid.JumpPower = 0
		charHumanoid.PlatformStand = true
		charHumanoid.AutoRotate = false
		local Multiplier = script.Parent.PrimaryPart:GetMass() * 1000
		char.PrimaryPart:ApplyImpulse(Multiplier * character.PrimaryPart.CFrame.LookVector)
		ragdoll(char)
		connection:Disconnect()
		RagdollValue.Value = true
	end)
	wait(1)
	connection:Disconnect()

	wait(4)
	if char then
		if not charHumanoid then charHumanoid = char:WaitForChild("Humanoid",5) or char:FindFirstChildWhichIsA("Humanoid") end
		if charHumanoid then 
			charHumanoid:ChangeState(Enum.HumanoidStateType.GettingUp) 
			charHumanoid.WalkSpeed = 16 
			charHumanoid.JumpPower = 50
			charHumanoid.AutoRotate = true
			charHumanoid.PlatformStand = false
			charHumanoid.Jump = true
		else warn("No humanoid!", char.Name)
			for _, child in ipairs(char:GetChildren()) do
				print(child.Name)
			end
		end
		if char.PrimaryPart then
			char:MoveTo(char.PrimaryPart.Position + Vector3.new(0,2,0))
		end
		unragdoll(char) 
	end
	if RagdollValue then
		RagdollValue.Value = false
	end
	debounce = false
end)

image

1 Like

I’ve found out why a player will be rag-dolled forever. If you slap a player and leave the game, the player you slapped will be forever rag-dolled, but still it sometimes kills the player.