Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. --[[
  2.  
  3.  
  4.  
  5. Psudar
  6. 7/17/2019
  7.  
  8.  
  9. How to use:
  10. --Make sure the script is parented to the hat model containing all the parts and such
  11. --Make sure theres a click detector also parented directly to the hat model
  12. --Make sure theres a psuedo head inside of the hat model, this is for positioning the hat however you may want.
  13.  
  14. Cheers.
  15. ]]
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. local hatModel = script.Parent --intitial model containing parts
  23. local clickDetector = hatModel:WaitForChild("ClickDetector") --clickdetector is for detecting clicks hehe
  24.  
  25. local function weldParts(part0, part1) -- welds the 2 parts based on their position
  26.  
  27. local newWeld = Instance.new("Weld")
  28. newWeld.Part0 = part0
  29. newWeld.Part1 = part1
  30. newWeld.C0 = CFrame.new()
  31. newWeld.C1 = part1.CFrame:toObjectSpace(part0.CFrame)
  32. newWeld.Parent = part0
  33.  
  34. end
  35.  
  36. local function onClicked(player) --player who clicked will be returned when called from event
  37.  
  38. if not player.Character:FindFirstChild(hatModel.Name) then
  39.  
  40. if player.Character:FindFirstChild("Head") then --check for a head
  41.  
  42. local playerHead = player.Character:FindFirstChild("Head") --save their head
  43. local newModel = hatModel:Clone() --clone the intitial model (the one this script is parented to)
  44. local newHead = newModel:WaitForChild("Head")--get the head from the new model, will be used for positioning later
  45.  
  46. newModel.PrimaryPart = newHead --set primary part to the head
  47. newModel:SetPrimaryPartCFrame(playerHead.CFrame) --set the primary parts cframe to the player's head
  48. newModel:SetPrimaryPartCFrame(playerHead.CFrame) -- puts the head into the head
  49. newModel.PrimaryPart:Destroy() --destroy the new head
  50.  
  51. for _, part in pairs (newModel:GetDescendants()) do --cycle through model descendants (everything inside of it)
  52. if part:IsA("BasePart") then --check for if its a part
  53. weldParts(playerHead, part) --call weld function on every part, welding it to the player's
  54. part.CanCollide = false
  55. part.Anchored = false
  56. end
  57. end
  58.  
  59. newModel.Parent = player.Character --set model parent to player's character
  60.  
  61. end
  62. else
  63. player.Character:FindFirstChild(hatModel.Name):Destroy() --removes hat
  64. end
  65. end
  66.  
  67. clickDetector.MouseClick:Connect(onClicked)
  68.  
  69.  
  70.  
  71.  
  72.  
  73. ------------------//END SCRIPT\\---------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement