So i have a avatar editor here and i want to make it where i can add charactermesh (Body parts) to the editor. or make them packages that when u equip it throws the meshes on your body and saves
-This is script1
local items = game.ReplicatedStorage:WaitForChild("CharacterItems")
local re = game.ReplicatedStorage:WaitForChild("CharacterCreatorRE")
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("DataSTORE_2010EYDRaWRx3RO_BLOXIARO_223b3h42")
--Function to save data
function saveData(player)
local currentItems = {}
for i, item in pairs(player.CurrentItems:GetChildren()) do
table.insert(currentItems, item.Name)
end
ds:SetAsync(player.UserId, currentItems)
end
function loadAvatar(player)
local currentItems = player.CurrentItems
local character = player.Character or player.CharacterAdded:Wait()
for i, child 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
for i, child in pairs(character.Head:GetChildren()) do
if child:IsA("Decal") then
child:Destroy()
end
end
for i, item in pairs(currentItems:GetChildren()) do
if items:FindFirstChild(item.Name, true) then
if item:IsA("Shirt") then
item:Clone().Parent = character
elseif item:IsA("Pants") then
item:Clone().Parent = character
elseif item:IsA("Decal") then
item:Clone().Parent = character
elseif item:IsA("ShirtGraphic") then
item:Clone().Parent = character
elseif item:IsA("Accessory") then
character.Humanoid:AddAccessory(item:Clone())
end
end
end
end
--Load player with last saved items
game.Players.PlayerAdded:Connect(function(player)
local currentItems = Instance.new("Folder", player)
currentItems.Name = "CurrentItems"
player.CharacterAdded:Connect(function(character)
loadAvatar(player)
end)
local data = ds:GetAsync(player.UserId) or {}
for i, itemName in pairs(data) do
if items:FindFirstChild(itemName, true) then
local itemType = items:FindFirstChild(itemName, true):FindFirstChildOfClass("Shirt") or items:FindFirstChild(itemName, true):FindFirstChildOfClass("ShirtGraphic") or items:FindFirstChild(itemName, true):FindFirstChildOfClass("Decal") or items:FindFirstChild(itemName, true):FindFirstChildOfClass("Pants") or items:FindFirstChild(itemName, true)
itemType:Clone().Parent = currentItems
end
end
loadAvatar(player)
end)
--Save items currently equipped by user
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
--Equip new items
re.OnServerEvent:Connect(function(player, itemsList)
if itemsList and player.Character then
for i, child in pairs(player.Character:GetChildren()) do
--child:IsA("CharacterMesh") or
if child:IsA("Shirt") or child:IsA("Pants") or child:IsA("ShirtGraphic") or child:IsA("Decal") or child:IsA("Accessory") then
child:Destroy()
end
end
for i, child in pairs(player.Character.Head:GetChildren()) do
--child:IsA("CharacterMesh") or
if child:IsA("Decal") then
child:Destroy()
end
end
player.CurrentItems:ClearAllChildren()
for i, item in pairs(itemsList) do
if items:FindFirstChild(item, true) then
local newItem = items:FindFirstChild(item, true):Clone()
if newItem:IsA("Shirt") then
if player.Character:FindFirstChildOfClass("Shirt") then
if player.CurrentItems:FindFirstChild(player.Character:FindFirstChildOfClass("Shirt").Name) then
player.CurrentItems[player.Character:FindFirstChildOfClass("Shirt").Name]:Destroy()
end
player.Character:FindFirstChildOfClass("Shirt"):Destroy()
end
newItem.Parent = player.Character
elseif newItem:IsA("Pants") then
if player.Character:FindFirstChildOfClass("Pants") then
if player.CurrentItems:FindFirstChild(player.Character:FindFirstChildOfClass("Pants").Name) then
player.CurrentItems[player.Character:FindFirstChildOfClass("Pants").Name]:Destroy()
end
player.Character:FindFirstChildOfClass("Pants"):Destroy()
end
newItem.Parent = player.Character
elseif newItem:IsA("Decal") then
if player.Character.Head:FindFirstChildOfClass("Decal") then
if player.CurrentItems:FindFirstChild(player.Character.Head:FindFirstChildOfClass("Decal").Name) then
player.CurrentItems[player.Character.Head:FindFirstChildOfClass("Decal").Name]:Destroy()
end
player.Character.Head:FindFirstChildOfClass("Decal"):Destroy()
end
newItem.Parent = player.Character.Head
elseif newItem:IsA("ShirtGraphic") then
if player.Character:FindFirstChildOfClass("ShirtGraphic") then
if player.CurrentItems:FindFirstChild(player.Character:FindFirstChildOfClass("ShirtGraphic").Name) then
player.CurrentItems[player.Character:FindFirstChildOfClass("ShirtGraphic").Name]:Destroy()
end
player.Character:FindFirstChildOfClass("ShirtGraphic"):Destroy()
end
newItem.Parent = player.Character
elseif newItem:IsA("Accessory") then
player.Character.Humanoid:AddAccessory(newItem)
end
newItem:Clone().Parent = player.CurrentItems
end
end
end
end)
-this is script 2
local items = game.ReplicatedStorage:WaitForChild("CharacterItems")
local re = game.ReplicatedStorage:WaitForChild("CharacterCreatorRE")
local MarketplaceService = game:GetService("MarketplaceService")
local bc1ID = 272441842 -- Change to your Gamepass ID
local Turboid = 873417743
local Templates = game.ReplicatedStorage.Templates
local player = game.Players.LocalPlayer
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, bc1ID)
local TurboPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, Turboid)
local frame = script.Parent.Parent.AvatarFrame
local button = script.Parent.Parent.Topbar.SideBar.Character
frame.Visible = false
button.Visible = true
local currentItems = {}
--Open and close GUI
button.MouseButton1Click:Connect(function()
currentItems = {}
for i, currentItem in pairs(game.Players.LocalPlayer:WaitForChild("CurrentItems"):GetChildren()) do
table.insert(currentItems, currentItem.Name)
end
for x, child in pairs(frame.CharacterViewportFrame:GetChildren()) do
if child:IsA("Camera") or child:IsA("Model") then child:Destroy() end
end
local character = game.Players.LocalPlayer.Character
character.Archivable = true
local characterModel = character:Clone()
characterModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
characterModel.Name = "Character"
local camera = Instance.new("Camera")
camera.Parent = frame.CharacterViewportFrame
frame.CharacterViewportFrame.CurrentCamera = camera
local scenemodel = game.Workspace.AVatarScene:Clone()
scenemodel.Parent = frame.CharacterViewportFrame
camera.CFrame = CFrame.new(characterModel.PrimaryPart.Position + characterModel.PrimaryPart.CFrame.LookVector * 5, characterModel.PrimaryPart.Position)
characterModel.Parent = frame.CharacterViewportFrame
--camera.CFrame = CFrame.new(characterModel.PrimaryPart.Position + characterModel.PrimaryPart.CFrame.LookVector * 5, characterModel.PrimaryPart.Position)
frame.Visible = true
end)
frame.ConfirmTextButton.MouseButton1Click:Connect(function()
re:FireServer(currentItems)
end)
--Setup character creator GUI
local function setupGui()
for i, child in pairs(frame.DropDown:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
for x, category in pairs(items:GetChildren()) do
local categoryName = category.Name
local newCategoryButton = Templates.Choices:Clone()
newCategoryButton.Text = categoryName
newCategoryButton.MouseButton1Click:Connect(function()
for y, child in pairs(frame.ItemsScrollingFrame:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end
end
frame.DropDown.Visible = false
local debounce = false
for z, item in pairs(category:GetChildren()) do
local itemType = item:FindFirstChildOfClass("Shirt")or item:FindFirstChildOfClass("ShirtGraphic") or item:FindFirstChildOfClass("Pants") or item
local itemName = itemType.Name
local newItemButton = Templates.AvatarItem:Clone()
newItemButton.Name = itemName
newItemButton.ItemName.Text = itemName
if item:GetAttribute("Limited") then
newItemButton.TagsFrame.LimitedTag.Visible = true
end
if item:GetAttribute("BuildersClub") then
newItemButton.TagsFrame.BCTAG.Visible = true
end
if newItemButton.Name == "BCHardHat" then
newItemButton.Visible = false
if hasPass then
newItemButton.Visible = true
end
elseif newItemButton.Name == "TBCHardHat" then
newItemButton.Visible = false
if TurboPass then
newItemButton.Visible = true
end
elseif newItemButton.Name == "TrophyHat" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" or game.Players.LocalPlayer.Name == "Eljalapeno2000" or game.Players.LocalPlayer.Name == "BenwojRobloxGamer" then
newItemButton.Visible = true
end
elseif newItemButton.Name == "Headless" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" then
newItemButton.Visible = true
end
elseif newItemButton.Name == "BlankHead" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" then
newItemButton.Visible = true
end
elseif newItemButton.Name == "EPIK DOMINUS" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" then
newItemButton.Visible = true
end
elseif newItemButton.Name == "SceneEyes" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" then
newItemButton.Visible = true
end
elseif newItemButton.Name == "Obamaface" then
newItemButton.Visible = false
if game.Players.LocalPlayer.Name == "PixelLyricCreates" then
newItemButton.Visible = true
end
end
if table.find(currentItems, itemType.Name) then newItemButton.ImageLabel.ImageColor3 = Color3.fromRGB(255, 255, 255) end
local camera = Instance.new("Camera")
camera.Parent = newItemButton.ItemViewportFrame
newItemButton.ItemViewportFrame.CurrentCamera = camera
local itemModel = item:Clone()
local itemMainPart = itemModel:FindFirstChild("Handle") or itemModel.PrimaryPart
if itemModel:FindFirstChild("Humanoid") then
itemModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
local distance = 6
if itemMainPart.Name == "Handle" then distance = 2 end
camera.CFrame = CFrame.new(itemMainPart.Position + itemMainPart.CFrame.LookVector * distance, itemMainPart.Position)
newItemButton.MouseButton1Click:Connect(function()
if frame.CharacterViewportFrame:FindFirstChild("Character") and not debounce then
debounce = true
if not table.find(currentItems, itemType.Name) then
table.insert(currentItems, itemType.Name)
newItemButton.ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
local itemToApply = itemType:Clone()
if itemType:IsA("Shirt") then
if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt") then
for i, item in pairs(currentItems) do
if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("Shirt") then
table.remove(currentItems, i)
end
end
if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt").Name) then
frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt").Name).ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
end
for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
if child:IsA("Shirt") then child:Destroy() end
end
end
itemToApply.Parent = frame.CharacterViewportFrame.Character
elseif itemType:IsA("ShirtGraphic") then
if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic") then
for i, item in pairs(currentItems) do
if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("ShirtGraphic") then
table.remove(currentItems, i)
end
end
if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic").Name) then
frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic").Name).ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
end
for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
if child:IsA("ShirtGraphic") then child:Destroy() end
end
end
itemToApply.Parent = frame.CharacterViewportFrame.Character
elseif itemType:IsA("Pants") then
if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants") then
for i, item in pairs(currentItems) do
if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("Pants") then
table.remove(currentItems, i)
end
end
if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants").Name) then
frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants").Name).ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
end
for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
if child:IsA("Pants") then child:Destroy() end
end
end
itemToApply.Parent = frame.CharacterViewportFrame.Character
elseif itemType:IsA("Decal") then
if frame.CharacterViewportFrame.Character.Head:FindFirstChildOfClass("Decal") then
for i, item in pairs(currentItems) do
if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("Decal") then
table.remove(currentItems, i)
end
end
if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character.Head:FindFirstChildOfClass("Decal").Name) then
frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character.Head:FindFirstChildOfClass("Decal").Name).ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
end
for i, child in pairs(frame.CharacterViewportFrame.Character.Head:GetChildren()) do
if child:IsA("Decal") then child:Destroy() end
end
end
itemToApply.Parent = frame.CharacterViewportFrame.Character.Head
elseif itemType:IsA("Accessory") then
local c = frame.CharacterViewportFrame.Character
c.Parent = workspace
itemToApply.Parent = c
local a1 = itemToApply.Handle:FindFirstChildOfClass("Attachment")
local a0 = c.Head[a1.Name]
local weld = Instance.new("Weld")
weld.Part0 = a0.Parent
weld.Part1 = a1.Parent
weld.C0 = a0.CFrame
weld.C1 = a1.CFrame
weld.Parent = a0.Parent
-- frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Accessory").Name).WearBtn.Text = "Wear"
local po = itemToApply.Handle.Position - c.Head.Position
local ro = itemToApply.Handle.Orientation - c.Head.Orientation
c.Parent = frame.CharacterViewportFrame
itemToApply.Parent = c
local atch = itemToApply.Handle:FindFirstChildOfClass("Attachment")
itemToApply.Handle.CFrame = c.Head.CFrame * CFrame.new(po) * CFrame.Angles(math.rad(ro.Z), math.rad(ro.Y), math.rad(ro.X))
end
else
table.remove(currentItems, table.find(currentItems, itemType.Name))
newItemButton.ImageLabel.ImageColor3 = Color3.fromRGB(255, 176, 204)
frame.CharacterViewportFrame.Character[itemName]:Destroy()
end
end
wait(1)
debounce = false
end)
itemModel.Parent = newItemButton.ItemViewportFrame
newItemButton.Parent = frame.ItemsScrollingFrame
newItemButton.Size = UDim2.new(0, newItemButton.AbsoluteSize.X, 0, newItemButton.AbsoluteSize.Y)
frame.ItemsScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, frame.ItemsScrollingFrame.UIGridLayout.AbsoluteContentSize.Y)
end
end)
newCategoryButton.Parent = frame.DropDown
--newCategoryButton.Size = UDim2.new(0, newCategoryButton.AbsoluteSize.X, 0, newCategoryButton.AbsoluteSize.Y)
--frame.DropDown.CanvasSize = UDim2.new(0, frame.CategoriesScrollingFrame.UIListLayout.AbsoluteContentSize.X, 0, 0)
end
end
setupGui()
items.DescendantAdded:Connect(setupGui)