Save player's skincolor?

So what i want is a variable that saves the player’s skin colour before the script starts.

But i don’t know how i would do that, Can someone help?

I tried to find stuff about it on the forums but wasn’t very successful.

So currently i have

local DefaultColor =

What do i put after that to save the player’s skintone?

Thank you for ur time.

You’ll need to set up and use the DatabaseService with roblox, which is pretty simple.

All you’ll have to do is Gather the service, create a database and then require some data, or input some data. If you’d like to see the wiki, click here.

However, for an example of what you’d like to be done, I’ll show you it right here.

local DSS = game:GetService("DataStoreService")
local ColourStore = DSS:GetDataStore("YOUR_DATASTORE_HERE")
local DefaultColour = nil

local su, col = pcall(function()

   return ColourStore:GetAsync(player.UserId)

end)

if su then DefaultColour = col return end

Wouldn’t datastore save the skin even when they leave, If so i just want it to save once per script
Basically, I’m putting a script inside a player when they drink a potion
Then the script gets enabled and i only want the skin to save in that script and when the script gets destroyed the save gets removed

Then you just do DefaultColour = "Whatever_Colour"?

I’m pretty confused as to what you’re asking for.

Ok so i’m trying to save the Skincolor of the person who drank the potion.
For instance, My skin is white then i want the script to save that colour so when i make the players colour Black, After the effect is gone i want the skincolor to change to their normal color

Honestly sounds like you could just use a table.

table[Player] = {R = current.R, G = current.G, B = current.B}

current being the players current color.

As long as the table is defined outside of the local scope and in the global script you’d be able to grab it from a different function later on. Just check to see if table[Player] is valid.

So should i use table.insert to insert the current bodycolours?

You may want to insert them individually if they’re mapped to a certain part, and name them accordingly so you know for a fact the right body part is getting the right color.

1 Like

You can try something like this:

DrinkPotion.OnServerEvent:Connect(function(player)
     local skinColor = player.Character.BodyColors:Clone()
    player.Character.BodyColors:Destroy()
    --potion drinking stuff
    --here you would make a new body colors that makes the character black and parent it the character
   --wait after the position effect is done then destroy the black body colors
  skinColor.Parent = player.Character
end)

I would also suggest reading up on body colors

1 Like

Oh, Totally forgot about Body colors!

I’ll try that thank you!

1 Like

Oh when I was referring to saving the colors individually I was meaning via a bodycolors that way you could change them all with out deleting, but deleting would work too I suppose.

Yeah, But since i’m bad at scripting i’m always trying to find a way i understand (Obviously) And what you said is a lot of stuff i don’t understand yet.

What I’d personally do is to have a table to change the bodyparts color to, and have some sort of function to edit the bodypart’s colors whenever you need. (I’d recommend using BodyColors object for this.) I’d also store a copy for each player to keep track of what each players’ Colors are. And then you just need a way to save the plrs[Player].BodyColors for each player.

local Store = game:GetService("DataStoreService"):GetDataStore("bodyColorStore")
local black, white, red = Color3.fromRGB(0,0,0), Color3.fromRGB(255, 255, 255), Color3.fromRGB(255, 0, 0)

local DefaultColor = 
-- feel free to edit the colours as you like
{
  UpdateVersion = 0;
  HeadColor3 = white;
  RightArmColor3 = black;
  RightLegColor3 = red;
  LeftArmColor3 = white;
  RightArmColor3 = black;
  RightLegColor3 = white;
  TorsoColor3 = white;
}

function UpdateBodyColors(Character, Table)
    Table.UpdateVersion = nil
    local BodyColor = Character:FindFirstChild("BodyColor") or Instance.new("BodyColor")
    BodyColor.Parent = Character
    for i, v in pairs(Table) do
      BodyColor[i] = v
    end
end

local plrs = {}

game:GetService("Players").PlayerAdded:Connect(function(Player)
    local s, e = pcall(function()  
       plrs[Player] = {
         BodyColors = Store:GetAsync(Player.UserId) or DefaultColor;
       }
   end)
   if not s then
     warn(e)
     plrs[Player] = {
         BodyColors = DefaultColor;
     }
   end
   Player.CharacterAdded:Connect(function(Character)
       plrs[Player].Character = Character 
       UpdateBodyColors(plrs[Player].Character, plrs[Player].BodyColors)
  end)
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
    local s, e = pcall(function()    
      Store:UpdateAsync(Player.UserId, function(oldVal)
            if OldVal and OldVal.UpdateVersion == plrs[Player].BodyColors.UpdateVersion then
               plrs[Player].BodyColors.UpdateVersion = plrs[Player].BodyColors.UpdateVersion + 1
           else
               return oldVal
           end
           return plrs[Player].BodyColors 
      end)
   end)
   if not s then
      warn(e)
  end
end)

The only drawback to this is that for every time the table is updated, you’ll need to call UpdateBodyColors() to update the colors.

1 Like