First off, I would like to apologize for any mistakes I make during this post, any wrong sayings, etc. I’m VERY new to coding in general, so I’m very inexperienced.
With that being said, here’s my question:
How would one restore a player’s original/default body colors, upon a MouseClick?
Now I do know that the “BodyColors” utility object stores the original body colors of a player, however I’m unsure on how to apply said BodyColors to a player (upon a click)
I’ve tried making my own scripts, following solutions on the devforum, however they either have errors or I simply do not understand them.
I would greatly appreciate it if someone could help me out.
local click = script.Parent
click.MouseClick:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
if humanoid.Health > 0 then
local bodyColors = character:FindFirstChildOfClass("BodyColors")
if bodyColors then
if humanoid.RigType == Enum.HumanoidRigType.R6 then
for _, child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") then
if child.Name ~= "HumanoidRootPart" then
local childName = child.Name:gsub("%s", "")
child.BrickColor = bodyColors[childName.."Color"]
end
end
end
elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
for _, child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") then
if child.Name == "Head" then
child.BrickColor = bodyColors["HeadColor"]
elseif child.Name:match("^Right%a+Leg$") or child.Name == "RightFoot" then
child.BrickColor = bodyColors["RightLegColor"]
elseif child.Name:match("^Left%a+Leg$") or child.Name == "LeftFoot" then
child.BrickColor = bodyColors["LeftLegColor"]
elseif child.Name:match("^Right%a+Arm$") or child.Name == "RightHand" then
child.BrickColor = bodyColors["RightArmColor"]
elseif child.Name:match("^Left%a+Arm$") or child.Name == "LeftHand" then
child.BrickColor = bodyColors["LeftArmColor"]
elseif child.Name:match("Torso$") then
child.BrickColor = bodyColors["TorsoColor"]
end
end
end
end
end
end
end
end)
With the following, will use the Left Arm Color as an example.
script.Parent.Touched:Connect(function(hit)
if hit then hit.Parent:FindFirstChild("Humanoid")
hit.Parent:FindFirstChild("Body Colors").LeftArmColor = BrickColor.new(0,1,0)
Thank you for posting this and putting effort, but unfortunately, I received the following error; “Left ArmColor is not a valid member of BodyColors”
I am unable to correct it.
However, based off your script, I did create the following, which had okay results (as in no errors when clicking, but still not changing characters back to their original color)
local click = script.Parent
click.MouseClick:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
local bodyColors = character:FindFirstChildWhichIsA("BodyColors")
local LAC = bodyColors.LeftArmColor3
local G = LAC.G
local B = LAC.B
local R = LAC.R
humanoid.Parent:FindFirstChild("Body Colors").LeftArmColor3 = Color3.new(R,G,B)
end)
I believe the problem may be that the means I use to change the Body Colors of players in the first place, also essentially changes the “original” colors of said player. Because of this, when the script initiates itself, it does run properly, however it doesn’t appear to change the color because it’s deriving its R,G,B values from “BodyColors”, which had said values changed after the touched function (see previous reply)
This is just my guess on what the problem is, but so far I am unable to fix it.
Oh I see the issue, for R6 avatars I forgot to remove the whitespace from the limb’s names, i.e; Left Arm should be LeftArm etc. I’ve edited the script with that fix implemented.
But yes, if you’re modifying the player’s body colors then you’ll need to store their original body colors somewhere so that you can revert back to them when necessary.
Thank you for this, I’ve managed to save the original colors via a PlayerAdded event and _G!
Update: Unfortunately, I have so far been able to save only set Colors as a value, and I am still figuring out how to save the value of a player’s body colors when he joins.