Hello,
I am making a game where the player can adjust their body colors using a gui button and it works but when the player resets or rejoins the game, it reverts back to the player’s original body colors. I want it to be so body colors stay if adjusted in-game even if the player dies or leaves the server.
Here is the script in the button that changes body color:
local imageButton = script.Parent
imageButton.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if not character then
warn("Character is missing!")
return
end
-- Ensure the character parts exist
local head = character:FindFirstChild("Head")
local torso = character:FindFirstChild("Torso")
local leftArm = character:FindFirstChild("Left Arm")
local rightArm = character:FindFirstChild("Right Arm")
local leftLeg = character:FindFirstChild("Left Leg")
local rightLeg = character:FindFirstChild("Right Leg")
if torso then torso.BrickColor = BrickColor.new(Color3.fromRGB(234, 190, 211)) end
if leftLeg then leftLeg.BrickColor = BrickColor.new(Color3.fromRGB(228, 153, 179)) end
if rightLeg then rightLeg.BrickColor = BrickColor.new(Color3.fromRGB(228, 153, 179)) end
print("Body colors applied successfully!")
end)
I want the changed body color to stay even if the player resets or leaves the game and rejoin but no matter what I try, I cannot get it to work b/c it always ends up reverting to the original body colors.
This was my original solution to preventing player appearance from reseting on respawn if this helps (even though it doesn’t work):
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local appearanceData = {}
-- Store the player's appearance (mesh parts and accessories)
local function storeAppearance(character)
for _, part in pairs(character:GetChildren()) do
if part:IsA("MeshPart") or part:IsA("Accessory") then
appearanceData[part.Name] = part:Clone() -- Clone the parts and store them
end
end
end
-- Reapply the stored appearance
local function applyAppearance(character)
-- First, remove all existing parts from the new character
for _, part in pairs(character:GetChildren()) do
if part:IsA("MeshPart") or part:IsA("Accessory") then
part:Destroy() -- Remove existing parts
end
end
-- Reapply the stored parts (including accessories and mesh parts)
for _, partClone in pairs(appearanceData) do
partClone.Parent = character
end
end
-- Ensure the player's appearance persists upon respawn
player.CharacterAdded:Connect(function(character)
appearanceData = {} -- Reset appearance data
storeAppearance(character) -- Store the new appearance data
-- Apply the stored appearance after character has fully loaded
character:WaitForChild("HumanoidRootPart") -- Ensure the character is fully loaded
applyAppearance(character)
end)
end)
Let me know if your are able to help at all