For my game, I have a script that takes custom player data I loaded from the starter place of my game, and makes the player in the current place have it.
It relates to the appearance of the character so i need everything in the current character to be deleted so i can put in the new things.
For some reason the function Clear() doesnt run, and everything after it like the skin color thing doesnt run either.
I checked there are no problems with the datastore and it reads everything correctly.
Heres the script
local playerAssets = game.ReplicatedStorage.PlrCustomAssets
local HairPaths = {
-- Folder 1, Subfolder 1
[1] = {folder = "1", subfolder = "1", shirt = "1"},
[2] = {folder = "1", subfolder = "1", shirt = "2"},
[3] = {folder = "1", subfolder = "1", shirt = "3"},
[4] = {folder = "1", subfolder = "1", shirt = "4"},
-- Folder 1, Subfolder 2
[5] = {folder = "1", subfolder = "2", shirt = "1"},
[6] = {folder = "1", subfolder = "2", shirt = "2"},
[7] = {folder = "1", subfolder = "2", shirt = "3"},
[8] = {folder = "1", subfolder = "2", shirt = "4"},
-- Folder 2, Subfolder 1
[9] = {folder = "2", subfolder = "1", shirt = "1"},
[10] = {folder = "2", subfolder = "1", shirt = "2"},
[11] = {folder = "2", subfolder = "1", shirt = "3"},
[12] = {folder = "2", subfolder = "1", shirt = "4"},
-- Folder 2, Subfolder 2
[13] = {folder = "2", subfolder = "2", shirt = "1"},
[14] = {folder = "2", subfolder = "2", shirt = "2"},
[15] = {folder = "2", subfolder = "2", shirt = "3"},
[16] = {folder = "2", subfolder = "2", shirt = "4"},
-- Folder 3, Subfolder 1
[17] = {folder = "3", subfolder = "1", shirt = "1"},
[18] = {folder = "3", subfolder = "1", shirt = "2"},
[19] = {folder = "3", subfolder = "1", shirt = "3"},
[20] = {folder = "3", subfolder = "1", shirt = "4"},
-- Folder 3, Subfolder 2
[21] = {folder = "3", subfolder = "2", shirt = "1"},
[22] = {folder = "3", subfolder = "2", shirt = "2"},
[23] = {folder = "3", subfolder = "2", shirt = "3"},
[24] = {folder = "3", subfolder = "2", shirt = "4"}
-- Selection 25 will be bald
}
local ShirtPaths = {
-- Folder 1, Subfolder 1
[1] = {folder = "1", subfolder = "1", shirt = "1"},
[2] = {folder = "1", subfolder = "1", shirt = "2"},
[3] = {folder = "1", subfolder = "1", shirt = "3"},
[4] = {folder = "1", subfolder = "1", shirt = "4"},
-- Folder 1, Subfolder 2
[5] = {folder = "1", subfolder = "2", shirt = "1"},
[6] = {folder = "1", subfolder = "2", shirt = "2"},
[7] = {folder = "1", subfolder = "2", shirt = "3"},
[8] = {folder = "1", subfolder = "2", shirt = "4"},
-- Folder 1, Subfolder 3
[9] = {folder = "1", subfolder = "3", shirt = "1"},
[10] = {folder = "1", subfolder = "3", shirt = "2"},
[11] = {folder = "1", subfolder = "3", shirt = "3"},
[12] = {folder = "1", subfolder = "3", shirt = "4"},
-- Folder 2, Subfolder 1
[13] = {folder = "2", subfolder = "1", shirt = "1"},
[14] = {folder = "2", subfolder = "1", shirt = "2"},
[15] = {folder = "2", subfolder = "1", shirt = "3"},
[16] = {folder = "2", subfolder = "1", shirt = "4"},
-- Folder 2, Subfolder 2
[17] = {folder = "2", subfolder = "2", shirt = "1"},
[18] = {folder = "2", subfolder = "2", shirt = "2"},
[19] = {folder = "2", subfolder = "2", shirt = "3"},
[20] = {folder = "2", subfolder = "2", shirt = "4"},
-- Folder 2, Subfolder 3
[21] = {folder = "2", subfolder = "3", shirt = "1"},
[22] = {folder = "2", subfolder = "3", shirt = "2"},
[23] = {folder = "2", subfolder = "3", shirt = "3"},
[24] = {folder = "2", subfolder = "3", shirt = "4"}
}
local SkinColors = {
[1] = Color3.fromRGB(255, 232, 193),
[2] = Color3.fromRGB(255, 202, 142),
[3] = Color3.fromRGB(253, 174, 110),
[4] = Color3.fromRGB(214, 154, 106),
[5] = Color3.fromRGB(130, 87, 70),
[6] = Color3.fromRGB(67, 54, 49),
}
local function Clear(Character)
for _, child:Instance in pairs(Character:GetChildren()) do
if child:IsA("Shirt") or child:IsA("Pants") or child:IsA("Accessory") or child:IsA("ShirtGraphic") then
child:Destroy()
end
end
end
----------------------------------
local Players = game.Players
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("SaveFileData")
game.Players.PlayerAdded:Connect(function(Player)
-- Get their current save
local currentSave = DataStore:GetAsync(Player.UserId.."-currentSave")
print(currentSave)
-- Get their customization data
local customizationData = DataStore:GetAsync(Player.UserId.."-file"..currentSave.."-customizationData")
--[[
local customizationData = {
SkinSel = script:GetAttribute("skinSel"),
ShirtSel = script:GetAttribute("shirtSel"),
PantsSel = script:GetAttribute("pantsSel"),
HairSel = script:GetAttribute("hairSel"),
AccSel = script:GetAttribute("accSel")
}
this is the format of what the customizationData should look like
]]--
if customizationData then
print("Has data")
else
print("Glitch")
end
local SkinSel = customizationData.SkinSel
local ShirtSel = customizationData.ShirtSel
local PantsSel = customizationData.PantsSel
local HairSel = customizationData.HairSel
local AccSel = customizationData.AccSel
local SkinToneColor = SkinColors[SkinSel]
Player.CharacterAppearanceLoaded:Connect(function(Character)
print("Character loaded")
wait(0.1)
Clear(Character)
local bodyParts = {
Character.Head,
Character.Torso,
Character["Left Arm"],
Character["Right Arm"],
Character["Left Leg"],
Character["Right Leg"]
}
for _, part in pairs(bodyParts) do
part.Color = SkinToneColor
end
end)
end)
u can ignore the first 3 tables, its just for loading purposes in the script
It always prints "Has Data" so i know theres no problem there.