Character doesn't fling or gets pushed away after an explosion

Hello!
I made this script in serverscriptservice where if a player dies, his dead body gets cloned and he gets ragdolled too, blah blah blah.

but i noticed that when i made a grenade and a player gets blown up, he just falls to the ground and lays there, instead of flying up into the air or something like that.

heres what i mean:

but the character that gets invisible gets flung like i want it to.
any help?
oh and heres the grenade so you can test it out:

the script:

local players = game:GetService("Players")
local debris = game:GetService("Debris")

local CORPSE_LIFETIME = 30 -- Time in seconds before the ragdoll is removed

-- Function to create a ragdoll for R6 characters
local function makeRagDoll(doll)
	-- Iterate through all parts of the character and replace Motor6D joints with BallSocketConstraint
	for _, part in ipairs(doll:GetDescendants()) do
		if part:IsA("Motor6D") then
			-- Create a new BallSocketConstraint
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")

			-- Attach the constraint to the parts
			a1.Parent = part.Part0
			a2.Parent = part.Part1
			socket.Parent = part.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2

			-- Set attachment positions for the constraint based on the Motor6D joint's CFrame
			a1.CFrame = part.C0
			a2.CFrame = part.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true

			-- Destroy the original Motor6D joint to prevent conflict with the BallSocketConstraint
			part:Destroy()
		end
	end
end

-- Function to make the original character's parts invisible and non-collidable
local function makeOriginalInvisible(char)
	for _, part in ipairs(char:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Transparency = 1
			part.CanCollide = false
		end
	end
end

-- Function to handle the ragdoll process when a player dies
local function handleDeath(char)
	-- Clone the character to preserve its appearance
	char.Archivable = true
	local dChar = char:Clone()
	char.Archivable = false

	-- Remove HumanoidRootPart from the cloned ragdoll
	local humanoidRootPart = dChar:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart.Anchored = false -- Ensure HRP is unanchored
		humanoidRootPart:Destroy() -- Remove to avoid conflicts
	end

	if dChar then
		-- Position the ragdoll clone at the same location as the original character
		dChar.Parent = workspace
		dChar:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame())

		-- Make the ragdoll clone visible and apply physics
		for _, part in ipairs(dChar:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
				part.Anchored = false -- Ensure parts are unanchored
				part.Transparency = 0 -- Make visible
			end
		end

		-- Destroy the humanoid to stop the ragdoll from interacting with the game

		--[CHANGES:]

		local humanoid = dChar:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.Health = 0 -- sets health to 0
			humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- makes no one be able to see his life or name
			humanoid:ChangeState(Enum.HumanoidStateType.Dead) -- makes the player looks like dead for server
		end

		-- Apply ragdoll physics to the clone
		makeRagDoll(dChar)

		-- Add ragdoll to Debris service for automatic cleanup
		debris:AddItem(dChar, CORPSE_LIFETIME)
	else
		warn("Failed to clone character!")
	end

	-- Make the original character invisible
	makeOriginalInvisible(char)
end

-- Connect to player death event
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		humanoid.BreakJointsOnDeath = false -- Prevent automatic joint breaking
		humanoid.Died:Connect(function()
			print("Player Has Died!", player.Name)
			handleDeath(char)
		end)
	end)
end)

Thanks for reading!

NOTE: rig is r6

By the time the player has died, the force has been applied from the explosion. The ragdoll is only created after death (I.e. after the force has been applied to the original rig).

Account for this in your script and apply the same forces from the rig, to the ragdoll, and the ragdoll will move too.

Hello!

The problem could be that when the player ragdolls, the explosion already happened making the ragdoll not flinged.

To try to fix it, first kill the player, and then explode the grenade.

Your humanoidrootpart is breaking. You could set the explosion’s breakjoint raidus percent to 0, or create your own system.

i did, i want the character to fling, the cloned one to be exact

Maybe you could add BodyVelocity to the ragdoll clone.

1 Like

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