i have tried it like this in every possible way, but i always eoither get NO error at all or it says Nil when i cloned the character. i am very desperate at this point.
script.Parent.Humanoid.BreakJointsOnDeath = false
local function OnDied()
local character = script.Parent
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
warn("HumanoidRootPart not found")
return
end
local ClonedModel = script.Parent:Clone()
for _, joint in ipairs(ClonedModel:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
-- Set specific limit values if needed
-- socket.UpperAngle = 90
-- socket.TwistLowerAngle = -45
-- socket.TwistUpperAngle = 45
joint:Destroy()
end
end
ClonedModel.Parent = game.Workspace
local boomScript = script.ASSETS:FindFirstChild("BOOM")
if boomScript then
boomScript:Clone().Parent = script.Parent:FindFirstChild("HumanoidRootPart")
-- boomScript.Enabled = true -- Uncomment if needed
end
-- Remove the original character
end
script.Parent.Humanoid.Died:Connect(OnDied)
maybe add some debugs like these and comment whatever doesn’t work. if you cant find the cause:
script.Parent.Humanoid.BreakJointsOnDeath = false
local function OnDied()
local character = script.Parent
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then
warn("HumanoidRootPart not found")
return
end
local ClonedModel = script.Parent:Clone()
for _, joint in ipairs(ClonedModel:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
if joint.Part0 and joint.Part1 then
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint:Destroy()
else
warn("Motor6D joint parts not found")
end
end
end
ClonedModel.Parent = game.Workspace
local boomScript = script.ASSETS:FindFirstChild("BOOM")
if boomScript then
local clonedBoomScript = boomScript:Clone()
clonedBoomScript.Parent = ClonedModel:FindFirstChild("HumanoidRootPart")
else
warn("script not found in ASSETS")
end
character:Destroy()
end
script.Parent.Humanoid.Died:Connect(OnDied)