Making My Ragdoll Turn Grey After Death

  • What are you attempting to achieve? (Keep it simple and clear)
    Get the players skin color to grey after his death

Hi! so i have been recently trying to script my ragdoll, and it works perfectly, however i want the dead body of the ragdoll to stay in the workspace and change the skin color to grey. Any help is appreciated

NOTE: i am new to scripting so i may not understand some things. Thanks!

Heres the script.

local humanoid = script.Parent:WaitForChild('Humanoid')

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	for index,joint in pairs(script.Parent: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
			joint:Destroy()
		end
	end
end)

ok so every humanoid should contain a body colors instance, you can set the values in there to any color you would like! For instance

local bc = script.Parent:FindFirstChild("BodyColors") -- the body colors
local deathColor = color3.new(89, 88, 86) -- color to set it to

-- do this to set color of BodyColors
bc.HeadColor3 = deathColor
bc.LeftArmColor3 = deathColor
bc.LeftLegColor3 = deathColor
bc.RightArmColor3 = deathColor
bc.RightLegColor3 = deathColor
bc.TorsoColor3 = deathColor

now thats how you set the colors, now if the character that died is a players character then youre gonna need to do this,

Basically the character will get deleted after a bit since its the players character, we need to clone it in order for it to not get deleted.

local oldChar script.Parent

humanoid.died:Once(function()
    local newChar = oldChar:Clone() -- clone the character cause the old one will delete
    oldChar:Destroy() -- remove it
end)

Next you’d just need to do your ragdoll code on the newChar instead of the old char.

Hope this helps you get started!

1 Like

Thanks alot! I do have a question. Do i put it in the same script? I mean probably yes but, id love to know if i should put it under the script or above. Thanks

Yes defiantly put this in the same script! It’ll make things more organized in the future!
: D

1 Like

It works perfectly, but after roblox studio did a auto save, something broke. i get 2 errors.

Player:Move has been called, but has no Humanoid
Workspace.TheTalkingMan2022.RagdollScript:35: attempt to index nil with ‘HeadColor3’

any fixes?

Can I see your code? Anyhow I dont think the first one is that big of a deal and I wouldnt worry about it to much. The second one I think I needa see your code for first :3

alright, here it is.

local humanoid = script.Parent:WaitForChild('Humanoid')

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	for index,joint in pairs(script.Parent: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
			joint:Destroy()
		end
	end
end)

local bc = script.Parent:FindFirstChild("BodyColors") -- the body colors
local deathColor = Color3.new(89, 88, 86) -- color to set it to

-- do this to set color of BodyColors
bc.HeadColor3 = deathColor
bc.LeftArmColor3 = deathColor
bc.LeftLegColor3 = deathColor
bc.RightArmColor3 = deathColor
bc.RightLegColor3 = deathColor
bc.TorsoColor3 = deathColor

local oldChar = script.Parent

humanoid.died:Once(function()
	local newChar = oldChar:Clone() -- clone the character cause the old one will delete
	oldChar:Destroy() -- remove it
end)

i fixed the code a little bit, since you forgot to capitalise some stuff and forgot to put a = sign :wink:

1 Like

it doesnt make my skin grey tho, even when i change the numbers

Hmm so what we need to do here is combine some of the code you got here:

-- char --
local char = script.Parent

-- values
local humanoid = char:WaitForChild('Humanoid') -- the body colors
local deathColor = Color3.new(89, 88, 86) -- color to set it to

humanoid.BreakJointsOnDeath = false

-- functions
local function setBodyColors(bc) -- set body colors
   -- do this to set color of BodyColors
	bc.HeadColor3 = deathColor
	bc.LeftArmColor3 = deathColor
	bc.LeftLegColor3 = deathColor
	bc.RightArmColor3 = deathColor
	bc.RightLegColor3 = deathColor
	bc.TorsoColor3 = deathColor 
end
-- main code

humanoid.Died:Once(function() -- died!
        
    local newChar = char:Clone() -- clone the character cause the old one will delete
    newChar.Parent = workspace -- parent the new character so we can see it
    setupBodyColors(newChar:FindFirstChild("BodyColors") -- setup body colors
    char:Destroy() -- remove the old character
    -- do stuff
	for index,joint in pairs(newChar: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
			joint:Destroy()
		end
	end
end)

I left some comments so you can read them to know what the code does.
Now also I recommend reading some basic tutorial that’ll help you with some more basic stuff, itll help a lot in the long run!

1 Like

Alright thanks! I will test it out.

also does it go into startercharacterscripts? because mine is a server script not a local…

hmm thats really up to you Ig. Theres a lot of server-client stuff we could get into but honestly dont think nows the best time to get into that

alright, Thanks for the help! Im sure i will need more help in the future, for now thanks alot!

1 Like

it works perfectly, although you did forget to write BreakJointsOnDeath = false :wink:

1 Like

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