So I’m making this script where if the player is swimming it changes the Infected value to true then it changes the player’s Body Colors to blue. But I want it so where if the infected value is false then the player’s body colors go back to their default. How can I do this? 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
-- default player color
end
end
end)
Inside the player character there is a value called BodyColors that you can use to get the players original body color, even if you changed it. Like this for example:
local player = game.Players.LocalPlayer
local character = player:WaitForChild("Character")
--What this is doing is getting the original rgb values for the players original body color from their
--head ONLY. I'm assuming the player has 1 overall color to them so taking the head color will
--reflect the players entire body color.
local bodyColorOriginal = character:FindFirstChildWhichIsA("BodyColors").HeadColor.r
local bodyColorOriginalG = character:FindFirstChildWhichIsA("BodyColors").HeadColor.g
local bodyColorOriginalB = character:FindFirstChildWhichIsA("BodyColors").HeadColor.b
--What this is doing is looping through the players body (including their hats) and setting them
--all to the original body color and material (default is plastic)
for i, bodyParts in pairs(character:GetChildren()) do
if bodyParts:IsA("BasePart") then
bodyParts.Material = "Plastic"
bodyParts.Color = Color3.new(bodyColorOriginal, bodyColorOriginalG, bodyColorOriginalB)
elseif bodyParts:IsA("Accessory") then
bodyParts.Handle.Material = "Plastic"
bodyParts.Handle.Color = Color3.new(bodyColorOriginal, bodyColorOriginalG, bodyColorOriginalB)
end
end