-
What do you want to achieve? Keep it simple and clear!
I want to make it so that all the limbs of the character have .CanCollide enabled via a script. -
What is the issue? Include screenshots / videos if possible!
This is a ragdoll engine. It all works just fine, however, when the character’s clone ragdolls, the limbs i.e. arms and legs have .CanCollide disabled and it won’t turn on no matter what I do. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried doingobj.CanCollide = true
in the for loop in the script but it didnt work.
For simplicity, the script included here is the original ragdoll engine that does not have my modifications that I made in an attempt to enable .CanCollide.
- Replication steps:
- Make a server script in
ServerScriptService
- Add the following code:
--> SERVICES <--
local Players = game:GetService("Players")
--> SETUP <--
local Connections = {} :: {[Player]: {RBXScriptConnection}}
--> FUNCTIONS <--
local function RagdollCharacter(character: Model)
character.Archivable = true
local corpse = character:Clone()
corpse.Parent = game.Workspace
corpse.PrimaryPart = corpse:FindFirstChild("HumanoidRootPart")
-- Make corpse non-player controlled
for _, obj in corpse:GetChildren() do
if obj.Name == "Head" or obj.Name == "Torso" or obj.Name == "Left Arm" or obj.Name == "Right Arm" or obj.Name == "Left Leg" or obj.Name == "Right Leg" or obj.Name == "HumanoidRootPart" then
obj.CanCollide = true
obj.Anchored = false
elseif obj:IsA("Humanoid") then
obj.BreakJointsOnDeath = false
obj.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
obj.PlatformStand = true
end
end
-- Ragdoll the corpse
for _, motor in corpse:GetDescendants() do
if motor:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a0 = Instance.new("Attachment")
local a1 = Instance.new("Attachment")
a0.CFrame = motor.C0
a1.CFrame = motor.C1
a0.Parent = motor.Part0
a1.Parent = motor.Part1
socket.Attachment0 = a0
socket.Attachment1 = a1
socket.Parent = motor.Part1.Parent
motor.Part1.Velocity = Vector3.new(0, 0, 0)
motor.Part1.RotVelocity = Vector3.new(0, 0, 0)
motor.Enabled = false
motor.Part0 = nil
motor.Part1 = nil
end
end
-- Apply impulse for a dramatic effect
task.spawn(function()
local torso = corpse:FindFirstChild("Torso") or corpse.PrimaryPart
if torso then
torso:ApplyImpulse(torso.CFrame.LookVector * 200)
end
end)
-- Destroy corpse after 20 seconds
task.delay(120, function()
if corpse then
corpse:Destroy()
end
end)
return corpse
end
local function SetupCharacter(char: Model, player: Player)
local hum = char:WaitForChild("Humanoid") :: Humanoid
hum.BreakJointsOnDeath = false
hum.Died:Once(function()
-- Create corpse
local corpse = RagdollCharacter(char)
-- Hide the original character
for _, obj in char:GetChildren() do
if obj:IsA("Humanoid") then
obj.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
else
obj:Destroy()
end
end
-- Spectate the corpse
local camera = workspace.CurrentCamera
if camera then
camera.CameraSubject = corpse:FindFirstChildOfClass("Humanoid") or corpse.PrimaryPart
end
end)
end
local function SetupPlayer(player: Player)
Connections[player] = {}
-- Setup Character
local char = player.Character or player.CharacterAdded:Wait()
SetupCharacter(char, player)
table.insert(Connections[player], player.CharacterAdded:Connect(function(newChar)
SetupCharacter(newChar, player)
local camera = workspace.CurrentCamera
if camera then
camera.CameraSubject = newChar:FindFirstChildOfClass("Humanoid") or newChar.PrimaryPart
end
end))
end
--> EVENT HANDLING <--
for _, player in Players:GetPlayers() do
task.spawn(SetupPlayer, player)
end
Players.PlayerAdded:Connect(SetupPlayer)
Players.PlayerRemoving:Connect(function(player)
if Connections[player] then
for _, connection in Connections[player] do
connection:Disconnect()
end
Connections[player] = nil
end
end)
- Launch the game and reset/die.