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

Why Won't the Color Data Save?

Asked by 3 years ago

I'm trying to save the hair color in a datastore but for some reason it would just delete all customization things like hair, face, skin color, accessories etc. I have no idea why, it all works before I try saving the hair color. The hair is put into a folder inside head. Heres the Script to save the data:

game.ReplicatedStorage.CustomizeDataEvents.CustomizeData.OnServerEvent:Connect(function(plr)
    local char = plr.Character
    local CurrentHair = char.Head.Hair:FindFirstChildOfClass("MeshPart") or char.Head.Hair:FindFirstChildOfClass("UnionOperation") or char.Head.Hair:FindFirstChildOfClass("Part")
    local HairCol = CurrentHair.Color
    local HairColData = {HairCol.R, HairCol.G, HairCol.B}

    local data = {
        AccessId = plr.CustomizeDataFolder.AccessoryId.Value;
        FaceId = plr.CustomizeDataFolder.FaceId.Value;
        HairId = plr.CustomizeDataFolder.HairId.Value;
        SkinId = plr.CustomizeDataFolder.SkinId.Value;
        HairColData;
    }


    local success, errormessage = pcall(function()
        CustomizeDataStore:SetAsync("Player_"..plr.UserId, data)
    end)

    if success then
        print("Data Successfully Saved")
    else
        print("Error Saving Data")
        warn(errormessage)
    end

end)

And this is the script to load the hair color:

game.Players.PlayerAdded:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()

    local CurrentHair = char.Head.Hair:FindFirstChildOfClass("MeshPart") or char.Head.Hair:FindFirstChildOfClass("UnionOperation") or char.Head.Hair:FindFirstChildOfClass("Part")

    local data
    local success, errormessage = pcall(function()
        data = CustomizeDataStore:GetAsync("Player_"..plr.UserId)
    end)

    if success then
        print("Success Getting Hair Color Data")
        if CurrentHair then
            CurrentHair.Color = Color3.fromRGB(data.HairColData[1], data.HairColData[2], data.HairColData[3])
        end

    else
        print("Error Getting Hair Color Data")
        warn(errormessage)
    end

end)

Answer this question