Guest User

King of the Hat [Roblox]

a guest
Apr 8th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.67 KB | None | 0 0
  1. --HumanoidDescription--
  2. local Birthday = Instance.new("HumanoidDescription")
  3. Birthday.Face = 1428416217
  4. Birthday.HeadColor = Color3.new(211,190,150)
  5. Birthday.LeftArmColor = Color3.new(245,205,49)
  6. Birthday.RightArmColor = Color3.new(245,205,49)
  7. Birthday.LeftLegColor = Color3.new(164,189,71)
  8. Birthday.RightLegColor = Color3.new(164,189,71)
  9. Birthday.TorsoColor = Color3.new(167,94,155)
  10.  
  11. --Services--
  12. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  13. local ServerStorage = game:GetService("ServerStorage")
  14. local Players = game:GetService('Players')
  15.  
  16. --Variables--
  17. local Throw = ReplicatedStorage:WaitForChild("Throw")
  18. local Select = ReplicatedStorage:WaitForChild("Select")
  19. --local changeAppearance = ReplicatedStorage:WaitForChild('changeAppearance')
  20. local HatFolder = ServerStorage.Hats
  21. local HitboxFolder = ServerStorage.Hitboxes
  22.  
  23. --Script--
  24. Select.OnServerEvent:Connect(function(player, hatName)
  25.    
  26.     local character = player.Character
  27.     local hat = HatFolder:FindFirstChild(hatName)
  28.    
  29.     if hat then
  30.  
  31.         player.Character.Humanoid:ApplyDescription(Birthday) --Change Their Avatar To The Selected Character
  32.         --[[
  33.         if hat.Name == "Cole" then
  34.            
  35.             local Hitbox = HitboxFolder:FindFirstChild("HitboxBig")
  36.             local clonedHitbox = Hitbox:Clone()
  37.             clonedHitbox.CFrame = character.HumanoidRootPart.CFrame
  38.             Hitbox.Name = "Hitbox"
  39.             local hitboxWeld = Instance.new("WeldConstraint")
  40.             hitboxWeld.Part0 = clonedHitbox
  41.             hitboxWeld.Part1 = character.HumanoidRootPart
  42.             hitboxWeld.Parent = clonedHitbox
  43.             clonedHitbox.Parent = character
  44.            
  45.         elseif hat.Name == "CaptainHat" then
  46.            
  47.             local Hitbox = HitboxFolder:FindFirstChild("HitboxSmall")
  48.             local clonedHitbox = Hitbox:Clone()
  49.             clonedHitbox.CFrame = character.HumanoidRootPart.CFrame
  50.             Hitbox.Name = "Hitbox"
  51.             local hitboxWeld = Instance.new("WeldConstraint")
  52.             hitboxWeld.Part0 = clonedHitbox
  53.             hitboxWeld.Part1 = character.HumanoidRootPart
  54.             hitboxWeld.Parent = clonedHitbox
  55.             clonedHitbox.Parent = character
  56.            
  57.         else           
  58.             local Hitbox = HitboxFolder:FindFirstChild("HitboxNormal")
  59.             local clonedHitbox = Hitbox:Clone()
  60.             clonedHitbox.CFrame = character.HumanoidRootPart.CFrame
  61.             Hitbox.Name = "Hitbox"
  62.             local hitboxWeld = Instance.new("WeldConstraint")
  63.             hitboxWeld.Part0 = clonedHitbox
  64.             hitboxWeld.Part1 = character.HumanoidRootPart
  65.             hitboxWeld.Parent = clonedHitbox
  66.             clonedHitbox.Parent = character
  67.            
  68.         end    
  69.         --]]
  70.                    
  71.         local chosenHat = HatFolder:FindFirstChild(hat.Name)
  72.         local clonedHat = chosenHat:Clone()
  73.         clonedHat.Name = "Hat"
  74.         local head = character:WaitForChild("Head")
  75.         clonedHat.CFrame = head.CFrame * CFrame.new(0,1.5,0)
  76.         clonedHat.Parent = character
  77.        
  78.         --Weld The Hat To The Players Head
  79.         local weld = Instance.new("WeldConstraint")
  80.         weld.Name = "Weld"
  81.         weld.Part0 = clonedHat
  82.         weld.Part1 = head
  83.         weld.Parent = clonedHat
  84.        
  85.         --Picking The Hat Up--
  86.         clonedHat.Touched:Connect(function(hit)
  87.  
  88.             if hit.Name == "Left Leg" or hit.Name == "Right Leg" then
  89.    
  90.                 if hit:IsDescendantOf(character) then
  91.                    
  92.                     weld.Parent = clonedHat
  93.                    
  94.                 elseif not hit:IsDescendantOf(character) then
  95.                            
  96.                         local opponent = Players:GetPlayerFromCharacter(hit.Parent)
  97.  
  98.                             character:BreakJoints()
  99.                             wait(5)
  100.                             opponent.leaderstats.Points.Value = opponent.leaderstats.Points.Value + 1
  101.                            
  102.                     end
  103.                 end
  104.             end)
  105.                    
  106.     end
  107. end)
  108.  
  109. --Throwing The Hat--
  110. Throw.OnServerEvent:Connect(function(player, mouse)
  111.    
  112.     local character = player.Character
  113.     local clonedHat = character:FindFirstChild("Hat")
  114.     local weld = clonedHat:FindFirstChild("Weld")
  115.     local trail = Instance.new("Trail")
  116.     local att0 = Instance.new("Attachment")
  117.     local att1 = Instance.new("Attachment")
  118.    
  119.     if weld then
  120.         weld.Parent = nil
  121.        
  122.         local bodyVelocity = Instance.new("BodyVelocity")
  123.        
  124.         --Moving The Hat Forward--
  125.         bodyVelocity.MaxForce = Vector3.new(200,200,200)
  126.         bodyVelocity.Velocity = (character.HumanoidRootPart.CFrame.lookVector*25)
  127.         --bodyVelocity.Velocity = mouse.p
  128.         bodyVelocity.Parent = character:FindFirstChild("Hat")
  129.        
  130.         --Trail Effect On Hat--
  131.         trail.Parent = clonedHat
  132.         att0.Parent = clonedHat
  133.         att1.Parent = clonedHat
  134.         trail.Attachment0 = att0
  135.         trail.Attachment1 = att1
  136.         trail.Enabled = true
  137.         att0.Position = Vector3.new(.5,0,0)
  138.         att1.Position = Vector3.new(-.5,0,0)
  139.        
  140.         local touchConn
  141.        
  142.         touchConn = clonedHat.Touched:Connect(function(hit)
  143.             if hit.Parent:FindFirstChild("Humanoid") then
  144.                 if hit.Parent.Name ~= player.Name then
  145.                     hit.Parent:FindFirstChild("Hat").Weld.Parent = nil
  146.                    
  147.                     end
  148.                 end
  149.             end)
  150.        
  151.         wait(3)
  152.         bodyVelocity:Destroy()
  153.         trail.Enabled = false
  154.        
  155.     end
  156. end)
Advertisement
Add Comment
Please, Sign In to add comment