Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Char Customization---
- local DataStore = game:GetService("DataStoreService")
- local CharDataSave = DataStore:GetDataStore("CharDataSave")
- local rp = game:GetService("ReplicatedStorage")
- local Folder = rp:WaitForChild("Events")
- local Event = Folder:WaitForChild("ColorEvent1")
- local ShirtEvent1 = Folder:WaitForChild("ShirtEvent1")
- local PantsEvent1 = Folder:WaitForChild("PantsEvent1")
- local HairEvent1 = Folder:WaitForChild("HairEvent1")
- local FaceEvent1 = Folder:WaitForChild("FaceEvent1")
- local SaveEvent1 = Folder:WaitForChild("SaveEvent1")
- local chardataloaded = rp:WaitForChild("chardataloaded")
- local ContentProvider = game:GetService("ContentProvider")
- ---Thanks to The Venomous Owl---
- --//Actually most of his code is kinda inneficient so i made one myself. But nonetheless thanks anyway.
- function loadChar(plr)
- local plrName = plr.Name
- local char = plr.Character
- local HumDes = char:WaitForChild("HumanoidDescription")
- local SkinValue = plr.CharData.Skin.Value
- local currColor = tonumber(SkinValue)
- local humanoid = char.Humanoid
- local color = {
- "Pastel brown";
- "Light orange";
- "Nougat";
- "Reddish brown";
- "Dark orange"
- }
- print(plr.CharData.Skin.Value)
- print(color[currColor])
- char.Head.BrickColor = BrickColor.new(color[currColor])
- char.UpperTorso.BrickColor = BrickColor.new(color[currColor])
- char.RightUpperLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftUpperLeg.BrickColor = BrickColor.new(color[currColor])
- char.RightLowerLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftLowerLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftFoot.BrickColor = BrickColor.new(color[currColor])
- char.RightFoot.BrickColor = BrickColor.new(color[currColor])
- char.LowerTorso.BrickColor = BrickColor.new(color[currColor])
- char.RightHand.BrickColor = BrickColor.new(color[currColor])
- char.LeftHand.BrickColor = BrickColor.new(color[currColor])
- char.RightUpperArm.BrickColor = BrickColor.new(color[currColor])
- char.LeftUpperArm.BrickColor = BrickColor.new(color[currColor])
- char.RightLowerArm.BrickColor = BrickColor.new(color[currColor])
- char.LeftLowerArm.BrickColor = BrickColor.new(color[currColor])
- local humanoid = char:WaitForChild("Humanoid")
- local hairexist = char:FindFirstChild("Hair")
- if hairexist then
- if hairexist.Handle:FindFirstChild("HairAttachment") then
- hairexist:Destroy()
- end
- end
- local hair = game.Workspace.Hairs:WaitForChild(plr.CharData.Hair.Value):Clone()
- hair.Handle.Anchored = false
- hair.Parent = char
- hair.Name = "Hair"
- local Head = char:WaitForChild("Head")
- Head.face.Texture = "http://www.roblox.com/asset/?id="..plr.CharData.Face.Value
- char:FindFirstChild("Shirt").ShirtTemplate = "rbxassetid://"..plr.CharData.Shirt.Value
- char:FindFirstChild("Pants").PantsTemplate = "rbxassetid://"..plr.CharData.Pants.Value
- end
- --PlayerAdded
- game.Players.PlayerAdded:Connect(function(plr)
- local CharData = Instance.new("Folder",plr)
- CharData.Name = "CharData"
- local Skin = Instance.new("StringValue",CharData)
- Skin.Name = "Skin"
- Skin.Value = "nil"
- local Hair = Instance.new("StringValue",CharData)
- Hair.Name = "Hair"
- Hair.Value = "nil"
- local Pants = Instance.new("StringValue",CharData)
- Pants.Name = "Pants"
- Pants.Value = "nil"
- local Shirt = Instance.new("StringValue",CharData)
- Shirt.Name = "Shirt"
- Shirt.Value = "nil"
- local Face = Instance.new("StringValue",CharData)
- Face.Name = "Face"
- Face.Value = "nil"
- local good, info = pcall(function()
- return(CharDataSave:GetAsync(plr.UserId))
- end)
- print(plr.Name, "DataStoreRetrivalInformation", good, info)
- plr.CharData.Skin.Value = info.Skin
- plr.CharData.Shirt.Value = info.Shirt
- plr.CharData.Pants.Value = info.Pants
- plr.CharData.Hair.Value = info.Hair
- plr.CharData.Face.Value = info.Face
- if plr.CharData.Skin.Value ~= nil then
- wait(15)
- local chardataexist = true
- chardataloaded:FireClient(plr, chardataexist)
- else
- wait(15)
- local chardataexist = false
- chardataloaded:FireClient(plr, chardataexist)
- end
- --Find players humanoid
- plr.CharacterAppearanceLoaded:Connect(function(character)
- local humanoid = character:WaitForChild("Humanoid")
- -- save hats for later
- local accessories = {}
- for _, accessory in pairs(humanoid:GetAccessories()) do
- table.insert(accessories, accessory:Clone())
- end
- -- remove hats
- for _, bc in pairs(humanoid.Parent:GetChildren()) do
- if bc:IsA("BodyColors") then
- bc:Destroy()
- end
- end
- humanoid:RemoveAccessories()
- end)
- end)
- --Skin Colour--
- 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
- local char = plr.Character
- local color = {
- "Pastel brown";
- "Light orange";
- "Nougat";
- "Reddish brown";
- "Dark orange"
- }
- plr.CharData.Skin.Value = currColor
- char.Head.BrickColor = BrickColor.new(color[currColor])
- char.UpperTorso.BrickColor = BrickColor.new(color[currColor])
- char.RightUpperLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftUpperLeg.BrickColor = BrickColor.new(color[currColor])
- char.RightLowerLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftLowerLeg.BrickColor = BrickColor.new(color[currColor])
- char.LeftFoot.BrickColor = BrickColor.new(color[currColor])
- char.RightFoot.BrickColor = BrickColor.new(color[currColor])
- char.LowerTorso.BrickColor = BrickColor.new(color[currColor])
- char.RightHand.BrickColor = BrickColor.new(color[currColor])
- char.LeftHand.BrickColor = BrickColor.new(color[currColor])
- char.RightUpperArm.BrickColor = BrickColor.new(color[currColor])
- char.LeftUpperArm.BrickColor = BrickColor.new(color[currColor])
- char.RightLowerArm.BrickColor = BrickColor.new(color[currColor])
- char.LeftLowerArm.BrickColor = BrickColor.new(color[currColor])
- end)
- --Shirt--
- ShirtEvent1.OnServerEvent:Connect(function(plr, shirtID)
- print("Server Recieved")
- local char = plr.Character
- char:FindFirstChild("Shirt").ShirtTemplate = "rbxassetid://"..shirtID
- plr.CharData.Shirt.Value = shirtID
- end)
- --Pants--
- PantsEvent1.OnServerEvent:Connect(function(plr, pantsID)
- print("Pants Received")
- local char = plr.Character
- char:FindFirstChild("Pants").PantsTemplate = "rbxassetid://"..pantsID
- plr.CharData.Pants.Value = pantsID
- end)
- --Hair--
- HairEvent1.OnServerEvent:Connect(function(plr, currHair)
- print("Hair Received")
- local char = plr.Character
- local humanoid = char:WaitForChild("Humanoid")
- local hairexist = char:FindFirstChild("Hair")
- if hairexist then
- if hairexist.Handle:FindFirstChild("HairAttachment") then
- hairexist:Destroy()
- end
- end
- local hair = game.Workspace.Hairs:WaitForChild(currHair.Name):Clone()
- hair.Handle.Anchored = false
- hair.Parent = char
- hair.Name = "Hair"
- plr.CharData.Hair.Value = currHair.Name
- end)
- --Face--
- FaceEvent1.OnServerEvent:Connect(function(plr, currFace)
- print("Face Recieved")
- local char = plr.Character
- local Head = char:WaitForChild("Head")
- Head.face.Texture = "http://www.roblox.com/asset/?id="..currFace.Name
- plr.CharData.Face.Value = currFace.Name
- end)
- --Save--
- SaveEvent1.OnServerEvent:Connect(function(plr)
- loadChar(plr)
- print("Save Server Recieved")
- warn("Saving Character...")
- local charToSave = {
- ["Skin"] = plr.CharData.Skin.Value;
- ["Shirt"] = plr.CharData.Shirt.Value;
- ["Pants"] = plr.CharData.Pants.Value;
- ["Hair"] = plr.CharData.Hair.Value;
- ["Face"] = plr.CharData.Face.Value
- }
- local success, errormassage = pcall(function()
- CharDataSave:SetAsync(plr.UserId,charToSave)
- end)
- if success then
- warn("Character Saved!")
- else
- warn("Character Error!")
- warn(errormassage)
- end
- end)
- game.Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function(char)
- if player.CharData.Skin.Value ~= nil then
- loadChar(player)
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment