How can I change the players bodycolor using gui buttons and save it incase they teleport to another place/level or until they die

Im trying to make it so you can change your body color to green, red, blue, ect.

The problem is that I have no clue how to save it to a datastore and if I do save it how can i replicate it to another place?

character example

4 Likes

If you need to switch from complex and constantly changing HumanoidDescriptions then you can serialize the humanoid description then save that to a datastore, then you can decode it when you read from the datastore and reapply it when they spawn.

HumanoidDescription.AccessoryBlob and HumanoidDescription::GetAccessories() might be good starting points to decide how and what you want to serialize.

Converting the object to a JSON is probably easiest since you will just need to read in each property into a table and then call HttpService:JSONEncode

local HttpService = game:GetService("HttpService")
local SerializedDescription = HttpService:JSONEncode({
  HatAccessory = HumanoidDescription.HatAccessory,
  -- ... 
  -- ...
  -- ...
})

If you literally only need to save their body colors for when they spawn you can just make a key in a datastore and make a simple if-elseif branch to handle recoloring their current HumanoidDescription

local Color = ColorStore:GetAsync(Player.UserId) -- could simply be stored as a 3 element array { 255, 0, 0 }
local ColorObject = Color3.new(table.unpack(Color))
HumanoidDescription.HeadColor = ColorObject
-- ... 
2 Likes

I get how it works but Im clueless on how to set it up and save it.

local ColorStore = game:GetService("DataStoreService"):GetDataStore("PlayerColor")
local Player = game.Players.LocalPlayer
local HumanoidDescription = Player.Character:FindFirstChild("Humanoid"):IsA("HumanoidDescription")

local Color = ColorStore:GetAsync(Player.UserId)
local ColorObject = Color3.new(table.unpack(Color))
HumanoidDescription.HeadColor = ColorObject
-- ...