Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Tizzel40 243 Moderation Voter
6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
Wait i dont rly understand... Tizzel40 243 — 6y
0
Hold on, I'll edit my post LegitmateTrades 159 — 6y
0
k Tizzel40 243 — 6y
0
Edited. LegitmateTrades 159 — 6y
View all comments (2 more)
0
ok Tizzel40 243 — 6y
0
`MeshPart` are considered `BasePart` Vulkarin 581 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
You forgot MeshPart, also I used a debounce as well. Check my answer haha LegitmateTrades 159 — 6y
0
I did not forget mesh part what are you on about User#19524 175 — 6y
0
And you did BrickColor.new(BrickColor.new()). You inserted a brickcolor into a brickcolor User#19524 175 — 6y
0
You are only logging BasePart even though the Humanoid has a Mesh Part in it, also what are you on about? LegitmateTrades 159 — 6y
View all comments (8 more)
0
https://gyazo.com/f8640c8ba04f25bec22446801bb0ba2b The humanoid doesn't have a mesh part though??? MeshPart inherits from BasePart, so your point has been invalidated. User#19524 175 — 6y
0
incapaz are you saying when checking for mesh part I don't have to? I can just do :IsA("BasePart")? User#21908 42 — 6y
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. User#19524 175 — 6y
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 LegitmateTrades 159 — 6y
0
You said the Humanoid had the mesh parts. User#19524 175 — 6y
0
I meant to say Character, my bad. LegitmateTrades 159 — 6y
0
So I am correct. User#19524 175 — 6y
0
Just went in studio and tested it and it works, never mind. I apologize. LegitmateTrades 159 — 6y
Log in to vote
-2
Answered by 6 years ago

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)

Answer this question