Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. local addAccessory
  2. local removeAccessory
  3. do -- Appearance adding / removing
  4.     local function hasTag(parent, tag)
  5.         local tagValue = parent:FindFirstChild("AccessoryTag")
  6.         if tagValue and tagValue.ClassName == "StringValue" then
  7.             return tagValue.Value == tag
  8.         end
  9.         return false
  10.     end
  11.    
  12.     local function addTag(parent, tag)
  13.         local oldTag = parent:FindFirstChild("AccessoryTag")
  14.         if oldTag then
  15.             oldTag.Value = tag
  16.         else
  17.             local newTag = Instance.new("StringValue")
  18.             newTag.Name = "AccessoryTag"
  19.             newTag.Value = tag
  20.             newTag.Parent = parent
  21.         end
  22.     end
  23.    
  24.     local function weld(attachment0, attachment1)
  25.         local part0 = attachment0.Parent
  26.         local part1 = attachment1.Parent
  27.         local weld = Instance.new("Weld")
  28.         weld.Part0 = part0
  29.         weld.Part1 = part1
  30.         weld.C0 = attachment0.CFrame
  31.         weld.C1 = attachment1.CFrame
  32.         weld.Name = "["..attachment0.Name.." | "..attachment1.Name.."]"
  33.         weld.Parent = part1
  34.         return weld
  35.     end
  36.    
  37.     function addAccessory(character, accessory, tag)
  38.         local accessoryAttachment = accessory:FindFirstChildOfClass("Attachment")
  39.         if not accessoryAttachment then
  40.             for _, child in pairs(accessory:GetChildren()) do
  41.                 if child:IsA("BasePart") then
  42.                     accessoryAttachment = child:FindFirstChildOfClass("Attachment")
  43.                     if accessoryAttachment then break end
  44.                 end
  45.             end
  46.         end
  47.         if accessoryAttachment then
  48.             local characterAttachment = character:FindFirstChild(accessoryAttachment.Name, true)
  49.             if characterAttachment and characterAttachment.ClassName == "Attachment" then
  50.                 accessory.Parent = character
  51.                 weld(characterAttachment, accessoryAttachment)
  52.                 if type(tag) == "string" then
  53.                     addTag(accessory, tag)
  54.                 end
  55.             else
  56.                 warn("Appearance | attachment missing in character: "..tostring(accessoryAttachment))
  57.                 accessory:Destroy()
  58.             end
  59.         else
  60.             warn("Appearance | attachment missing for accessory: "..tostring(accessory))
  61.             accessory:Destroy()
  62.         end
  63.     end
  64.    
  65.     function removeAccessory(character, tag)
  66.         for _, child in pairs(character:GetChildren()) do
  67.             if child:IsA("Accoutrement") then
  68.                 if hasTag(child, tag) then
  69.                     child:Destroy()
  70.                 end
  71.             end
  72.         end
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement