Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I want to change a person's Skin color when I press "E" and it does but its PREMANENT!?

ok so here is the script.I want to change to persons skin Color to "Terra Cotta" and it does but the problem is how do I get their original Skin Color back when I press E? The person just stays as The Terra Cotta Color for ever...

local uis = game:GetService("UserInputService")
local ruse = false
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		game.Players.LocalPlayer.Character.UpperTorso.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftFoot.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftHand.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LowerTorso.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightFoot.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightHand.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightLowerArm.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightUpperArm.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightLowerLeg.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightUpperLeg.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.RightUpperArm.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftUpperLeg.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftLowerLeg.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftUpperArm.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.LeftLowerArm.BrickColor = BrickColor.new("Terra Cotta")
		game.Players.LocalPlayer.Character.Head.BrickColor = BrickColor.new("Terra Cotta")
	end
	end)
--local uis = game:GetService("UserInputService")
--uis.InputBegan:Connect(function(input)
--	if input.KeyCode == Enum.KeyCode.F then
--		
--	end
--	end)

By the way this is a local script.

3 answers

Save the skin color for each of the players parts in a temporary table when they press E the first time then make a debounce so for example:

local EPressed = false

if EPressed == false then
	--Change their color.
elseif EPressed == true then
	--Turn their color back
end

After the first time it will log their skin color for their parts in a temp table and when they press E the second time it grabs from that table for each part and changes it to the color logged.

Example

local EPressed = false
local player = game.Players.LocalPlayer
local colorTable = {}

if EPressed == false then
	EPressed = true
	for i,v in pairs(player.Character:GetChildren()) do
		if v:IsA("BasePart") or v:IsA("MeshPart") then
			table.Insert(colorTable, v.BrickColor)
			v.BrickColor = BrickColor.new("Terra Cotta")
		end
	end
elseif EPressed == true then
	EPressed = false
	for i,v in pairs(player.Character:GetChildren()) do
		if v:IsA("BasePart") or v:IsA("MeshPart") then
			v.BrickColor = BrickColor.new(colorTable[i])
		end
	end
end

6 comments

0

Wait i dont rly understand...

0

Hold on, I'll edit my post

0

k

0

Edited.

0

ok

0

MeshPart are considered BasePart

###You could loop through the parts and save their BrickColor. And adding on to LegitimateTrade's answer, you could have a boolean to check if it was pressed.

local Players = game:GetService("Players")
local player = Players.LocalPlayer -- to prevent having to type out the full thing
local character = player.Character or plr.CharacterAdded:Wait()
local enabled = false -- We will set to true when button is pressed
local tc = "Terra Cotta" -- brick colour
local bodyColours = {} -- blank table that we will add body colours to.

uis.InputBegan:Connect(function(input, gpe)
    if gpe then return end -- stop if they're chatting
    
    if input.KeyCode == Enum.KeyCode.E then
        enabled = not enabled -- set to the opposite of current state

        for _, v in pairs(character:GetChildren()) do -- loop through children
            if v:IsA("BasePart") then -- in the char, only parts have brick colours 
                table.insert(bodyColours, v.BrickColor) -- save obj
            end 
        end

        if enabled then -- if it's enabled
            for _, v in pairs(character:GetChildren()) do -- another for loop
                if v:IsA("BasePart") then v.BrickColor = BrickColor.new(tc) end
           end

        else-- it's not enabled, reset their brick colours

            for _, v in pairs(character:GetChildren()) do  
                if v:IsA("BasePart") then
                    for _, colour in pairs(bodyColours) do
                        v.BrickColor = colour
                    end
                end
            end

        end
    end
end)

12 comments

0

You forgot MeshPart, also I used a debounce as well. Check my answer haha

0

I did not forget mesh part what are you on about

0

And you did BrickColor.new(BrickColor.new()). You inserted a brickcolor into a brickcolor

0

You are only logging BasePart even though the Humanoid has a Mesh Part in it, also what are you on about?

0

https://gyazo.com/f8640c8ba04f25bec22446801bb0ba2b The humanoid doesn't have a mesh part though??? MeshPart inherits from BasePart, so your point has been invalidated.

0

incapaz are you saying when checking for mesh part I don't have to? I can just do :IsA("BasePart")?

0

That's exactly what I'm saying. People nowadays only use it to check ClassName, but they don't know it can also be used to check inheritance.

0

That is what he is trying to say however it is false I've tried it multiple times. Also if a character has no mesh parts what are all these: https://gyazo.com/06268569b9575aad0bd11c2a6617f781

0

You said the Humanoid had the mesh parts.

0

I meant to say Character, my bad.

0

So I am correct.

0

Just went in studio and tested it and it works, never mind. I apologize.

local uis = game:GetService("UserInputService") local ruse = false uis.InputBegan:Connect(function(input) local BodyColors = game:GetService("Players").LocalPlayer.Character:WaitForChild("Body Colors") if input.KeyCode == Enum.KeyCode.E and ruse == false then BodyColors.HeadColor3 = Color3.fromRGB(190, 104, 98) BodyColors.HeadColor3 = Color3.fromRGB(190, 104, 98) BodyColors.LeftArmColor3 = Color3.fromRGB(190, 104, 98) BodyColors.LeftLegColor3 = Color3.fromRGB(190, 104, 98) BodyColors.RightArmColor3 = Color3.fromRGB(190, 104, 98) BodyColors.RightLegColor3 = Color3.fromRGB(190, 104, 98) BodyColors.TorsoColor3 = Color3.fromRGB(190, 104, 98) ruse = true elseif input.KeyCode == Enum.KeyCode.E and ruse == true then BodyColors.HeadColor3 = Color3.fromRGB(255, 204, 153) BodyColors.HeadColor3 = Color3.fromRGB(255, 204, 153) BodyColors.LeftArmColor3 = Color3.fromRGB(255, 204, 153) BodyColors.LeftLegColor3 = Color3.fromRGB(255, 204, 153) BodyColors.RightArmColor3 = Color3.fromRGB(255, 204, 153) BodyColors.RightLegColor3 = Color3.fromRGB(255, 204, 153) BodyColors.TorsoColor3 = Color3.fromRGB(255, 204, 153) ruse = false end end)

This discussion is preserved as it was. New answers, comments, and votes are closed.