How to get the default BodyColor?

So I made this script where it copies the HeadColor3 Value of the BodyColors to a Color3 Value I made. So I want the player’s body color to change to blue if their humanoid state is Swimming. But if the State is Landed then it makes the body colors to their default. But I don’t know how to get the default Body Colors. This is my script:

local Humanoid = script.Parent:WaitForChild("Humanoid")

Humanoid.StateChanged:Connect(function(oldState, newState)
	if Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
		print("swimming")
		script.Infected.Value = true
	end
end)

Humanoid.StateChanged:Connect(function(oldState, newState)
	if Humanoid:GetState() == Enum.HumanoidStateType.Landed then
		print("landed")
		script.Infected.Value = false
	end
end)

local BColor = script.Parent:WaitForChild("Body Colors")
local IValue = script.Infected


IValue.Changed:Connect(function()
	if IValue.Value == true then
		BColor.HeadColor3 = Color3.new(0.145098, 0.823529, 0.972549)
		BColor.TorsoColor3 = Color3.new(0.145098, 0.823529, 0.972549)
		BColor.LeftArmColor3 = Color3.new(0.145098, 0.823529, 0.972549)
		BColor.RightArmColor3 = Color3.new(0.145098, 0.823529, 0.972549)
		BColor.LeftLegColor3 = Color3.new(0.145098, 0.823529, 0.972549)
		BColor.RightLegColor3 = Color3.new(0.145098, 0.823529, 0.972549)
	else if IValue.Value == false then
			BColor.HeadColor3 = Color3.new()
			BColor.TorsoColor3 = Color3.new()
			BColor.LeftArmColor3 = Color3.new()
			BColor.RightArmColor3 = Color3.new()
			BColor.LeftLegColor3 = Color3.new()
			BColor.RightLegColor3 = Color3.new()
		end
	end
end)

So what you could do is store each Color3 as a table and then use those cached values each time you want to restore the player’s default limb colors.

Here’s an example of how that could look:

local LIMB_NAMES = {
["HeadColor3"] = true;
["TorsoColor3"] = true;
["LeftArmColor3"] = true;
["RightArmColor3"] = true;
["LeftLegColor3"] = true;
["RightLegColor3"] = true;
}

local startLimbColors = {}

local function saveLimbColors() --//Caches the player's current limb colors
for limbName,_ in pairs(LIMB_NAMES) do
startLimbColors[limbName] = character.BodyColors[limbName]
end
end

local function loadLimbColors() --//Loads any cached limb color profile for the player
for limbName, color in pairs(startLimbColors) do
character.BodyColors[limbName] = color
end
end

Something like this should be what you’re looking for. :slight_smile:

2 Likes