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.
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
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
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
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!