Guest User

CharacterCust

a guest
Apr 8th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.88 KB | None | 0 0
  1.  
  2. ---Char Customization---
  3. local DataStore = game:GetService("DataStoreService")
  4. local CharDataSave = DataStore:GetDataStore("CharDataSave")
  5.  
  6. local rp = game:GetService("ReplicatedStorage")
  7. local Folder = rp:WaitForChild("Events")
  8. local Event = Folder:WaitForChild("ColorEvent1")
  9. local ShirtEvent1 = Folder:WaitForChild("ShirtEvent1")
  10. local PantsEvent1 = Folder:WaitForChild("PantsEvent1")
  11. local HairEvent1 = Folder:WaitForChild("HairEvent1")
  12. local FaceEvent1 = Folder:WaitForChild("FaceEvent1")
  13. local SaveEvent1 = Folder:WaitForChild("SaveEvent1")
  14. local chardataloaded = rp:WaitForChild("chardataloaded")
  15. local ContentProvider = game:GetService("ContentProvider")
  16.  
  17. ---Thanks to The Venomous Owl---
  18. --//Actually most of his code is kinda inneficient so i made one myself. But nonetheless thanks anyway.
  19. function loadChar(plr)
  20.    
  21.     local plrName = plr.Name
  22.     local char = plr.Character
  23.     local HumDes = char:WaitForChild("HumanoidDescription")
  24.     local SkinValue = plr.CharData.Skin.Value
  25.     local currColor = tonumber(SkinValue)
  26.     local humanoid = char.Humanoid
  27.    
  28.     local color = {
  29.         "Pastel brown";
  30.         "Light orange";
  31.         "Nougat";
  32.         "Reddish brown";
  33.         "Dark orange"
  34.     }
  35.     print(plr.CharData.Skin.Value)
  36.     print(color[currColor])
  37.     char.Head.BrickColor = BrickColor.new(color[currColor])
  38.     char.UpperTorso.BrickColor = BrickColor.new(color[currColor])
  39.     char.RightUpperLeg.BrickColor = BrickColor.new(color[currColor])
  40.     char.LeftUpperLeg.BrickColor = BrickColor.new(color[currColor])
  41.     char.RightLowerLeg.BrickColor = BrickColor.new(color[currColor])
  42.     char.LeftLowerLeg.BrickColor = BrickColor.new(color[currColor])
  43.     char.LeftFoot.BrickColor = BrickColor.new(color[currColor])
  44.     char.RightFoot.BrickColor = BrickColor.new(color[currColor])
  45.     char.LowerTorso.BrickColor = BrickColor.new(color[currColor])
  46.     char.RightHand.BrickColor = BrickColor.new(color[currColor])
  47.     char.LeftHand.BrickColor = BrickColor.new(color[currColor])
  48.     char.RightUpperArm.BrickColor = BrickColor.new(color[currColor])
  49.     char.LeftUpperArm.BrickColor = BrickColor.new(color[currColor])
  50.     char.RightLowerArm.BrickColor = BrickColor.new(color[currColor])
  51.     char.LeftLowerArm.BrickColor = BrickColor.new(color[currColor])
  52.  
  53.     local humanoid = char:WaitForChild("Humanoid")
  54.     local hairexist = char:FindFirstChild("Hair")
  55.  
  56.     if hairexist then
  57.         if hairexist.Handle:FindFirstChild("HairAttachment") then
  58.             hairexist:Destroy()
  59.         end
  60.     end
  61.  
  62.     local hair = game.Workspace.Hairs:WaitForChild(plr.CharData.Hair.Value):Clone()
  63.     hair.Handle.Anchored = false
  64.     hair.Parent = char
  65.     hair.Name = "Hair"
  66.  
  67.     local Head = char:WaitForChild("Head")
  68.     Head.face.Texture = "http://www.roblox.com/asset/?id="..plr.CharData.Face.Value
  69.  
  70.     char:FindFirstChild("Shirt").ShirtTemplate = "rbxassetid://"..plr.CharData.Shirt.Value
  71.  
  72.     char:FindFirstChild("Pants").PantsTemplate = "rbxassetid://"..plr.CharData.Pants.Value
  73.  
  74.  
  75. end
  76.  
  77.  
  78. --PlayerAdded
  79. game.Players.PlayerAdded:Connect(function(plr)
  80.    
  81.     local CharData = Instance.new("Folder",plr)
  82.     CharData.Name = "CharData"
  83.    
  84.     local Skin = Instance.new("StringValue",CharData)
  85.     Skin.Name = "Skin"
  86.     Skin.Value = "nil"
  87.    
  88.     local Hair = Instance.new("StringValue",CharData)
  89.     Hair.Name = "Hair"
  90.     Hair.Value = "nil"
  91.    
  92.     local Pants = Instance.new("StringValue",CharData)
  93.     Pants.Name = "Pants"
  94.     Pants.Value = "nil"
  95.    
  96.     local Shirt = Instance.new("StringValue",CharData)
  97.     Shirt.Name = "Shirt"
  98.     Shirt.Value = "nil"
  99.    
  100.     local Face = Instance.new("StringValue",CharData)
  101.     Face.Name = "Face"
  102.     Face.Value = "nil"
  103.    
  104.     local good, info = pcall(function()
  105.         return(CharDataSave:GetAsync(plr.UserId))
  106.     end)
  107.    
  108.     print(plr.Name, "DataStoreRetrivalInformation", good, info)
  109.     plr.CharData.Skin.Value = info.Skin
  110.     plr.CharData.Shirt.Value = info.Shirt
  111.     plr.CharData.Pants.Value = info.Pants
  112.     plr.CharData.Hair.Value = info.Hair
  113.     plr.CharData.Face.Value = info.Face
  114.    
  115.     if plr.CharData.Skin.Value ~= nil then
  116.         wait(15)
  117.         local chardataexist = true
  118.         chardataloaded:FireClient(plr, chardataexist)
  119.     else
  120.         wait(15)
  121.         local chardataexist = false
  122.         chardataloaded:FireClient(plr, chardataexist)
  123.     end
  124.    
  125.     --Find players humanoid
  126.     plr.CharacterAppearanceLoaded:Connect(function(character)
  127.         local humanoid = character:WaitForChild("Humanoid")
  128.        
  129.    
  130.         -- save hats for later
  131.         local accessories = {}
  132.         for _, accessory in pairs(humanoid:GetAccessories()) do
  133.             table.insert(accessories, accessory:Clone())
  134.         end
  135.  
  136.         -- remove hats
  137.         for _, bc in pairs(humanoid.Parent:GetChildren()) do
  138.             if bc:IsA("BodyColors") then
  139.                 bc:Destroy()
  140.             end
  141.         end
  142.         humanoid:RemoveAccessories()
  143.     end)
  144. end)
  145.  
  146. --Skin Colour--
  147. Event.OnServerEvent:Connect(function(plr, currColor) --Idk why but it seems like i gotta write Player first before writing the varible that was sent by the client
  148.    
  149.     local char = plr.Character
  150.     local color = {
  151.         "Pastel brown";
  152.         "Light orange";
  153.         "Nougat";
  154.         "Reddish brown";
  155.         "Dark orange"
  156.     }
  157.     plr.CharData.Skin.Value = currColor
  158.     char.Head.BrickColor = BrickColor.new(color[currColor])
  159.     char.UpperTorso.BrickColor = BrickColor.new(color[currColor])
  160.     char.RightUpperLeg.BrickColor = BrickColor.new(color[currColor])
  161.     char.LeftUpperLeg.BrickColor = BrickColor.new(color[currColor])
  162.     char.RightLowerLeg.BrickColor = BrickColor.new(color[currColor])
  163.     char.LeftLowerLeg.BrickColor = BrickColor.new(color[currColor])
  164.     char.LeftFoot.BrickColor = BrickColor.new(color[currColor])
  165.     char.RightFoot.BrickColor = BrickColor.new(color[currColor])
  166.     char.LowerTorso.BrickColor = BrickColor.new(color[currColor])
  167.     char.RightHand.BrickColor = BrickColor.new(color[currColor])
  168.     char.LeftHand.BrickColor = BrickColor.new(color[currColor])
  169.     char.RightUpperArm.BrickColor = BrickColor.new(color[currColor])
  170.     char.LeftUpperArm.BrickColor = BrickColor.new(color[currColor])
  171.     char.RightLowerArm.BrickColor = BrickColor.new(color[currColor])
  172.     char.LeftLowerArm.BrickColor = BrickColor.new(color[currColor])
  173. end)
  174.  
  175. --Shirt--
  176. ShirtEvent1.OnServerEvent:Connect(function(plr, shirtID)
  177.     print("Server Recieved")
  178.     local char = plr.Character
  179.     char:FindFirstChild("Shirt").ShirtTemplate = "rbxassetid://"..shirtID
  180.     plr.CharData.Shirt.Value = shirtID
  181. end)
  182.  
  183. --Pants--
  184. PantsEvent1.OnServerEvent:Connect(function(plr, pantsID)
  185.     print("Pants Received")
  186.     local char = plr.Character
  187.     char:FindFirstChild("Pants").PantsTemplate = "rbxassetid://"..pantsID
  188.     plr.CharData.Pants.Value = pantsID
  189. end)
  190.  
  191. --Hair--
  192. HairEvent1.OnServerEvent:Connect(function(plr, currHair)
  193.     print("Hair Received")
  194.     local char = plr.Character
  195.     local humanoid = char:WaitForChild("Humanoid")
  196.     local hairexist = char:FindFirstChild("Hair")
  197.  
  198.     if hairexist then
  199.         if hairexist.Handle:FindFirstChild("HairAttachment") then
  200.             hairexist:Destroy()
  201.         end
  202.     end
  203.    
  204.     local hair = game.Workspace.Hairs:WaitForChild(currHair.Name):Clone()
  205.     hair.Handle.Anchored = false
  206.     hair.Parent = char
  207.     hair.Name = "Hair"
  208.     plr.CharData.Hair.Value = currHair.Name
  209.    
  210. end)
  211.  
  212. --Face--
  213. FaceEvent1.OnServerEvent:Connect(function(plr, currFace)
  214.     print("Face Recieved")
  215.     local char = plr.Character
  216.     local Head = char:WaitForChild("Head")
  217.     Head.face.Texture = "http://www.roblox.com/asset/?id="..currFace.Name
  218.     plr.CharData.Face.Value = currFace.Name
  219. end)
  220.  
  221. --Save--
  222. SaveEvent1.OnServerEvent:Connect(function(plr)
  223.     loadChar(plr)
  224.  
  225.     print("Save Server Recieved")
  226.     warn("Saving Character...")
  227.     local charToSave = {
  228.         ["Skin"] = plr.CharData.Skin.Value;
  229.         ["Shirt"] = plr.CharData.Shirt.Value;
  230.         ["Pants"] = plr.CharData.Pants.Value;
  231.         ["Hair"] = plr.CharData.Hair.Value;
  232.         ["Face"] = plr.CharData.Face.Value
  233.     }
  234.    
  235.     local success, errormassage = pcall(function()
  236.         CharDataSave:SetAsync(plr.UserId,charToSave)
  237.     end)
  238.     if success then
  239.             warn("Character Saved!")
  240.            
  241.     else
  242.         warn("Character Error!")
  243.         warn(errormassage)
  244.     end
  245. end)
  246.  
  247. game.Players.PlayerAdded:Connect(function(player)
  248.     player.CharacterAdded:Connect(function(char)
  249.         if player.CharData.Skin.Value ~= nil then
  250.             loadChar(player)
  251.         end
  252.        
  253.     end)
  254. end)
Advertisement
Add Comment
Please, Sign In to add comment