Advertisement
Guest User

CreatePlayerProp

a guest
Feb 27th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. -- SERVICES
  2.  
  3. local ServerStorage = game:GetService("ServerStorage")
  4. local PhysicsService= game:GetService("PhysicsService")
  5. local CollectionService = game:GetService("CollectionService")
  6.  
  7. -- MODULES
  8.  
  9. local Modules = ServerStorage.Modules
  10.  
  11. -- ASSETS
  12.  
  13. local Assets = ServerStorage.Assets
  14. local Props = Assets.Props
  15.  
  16. -- VARIABLES
  17.  
  18. local Hitboxes = workspace.Hitboxes
  19.  
  20. -- FUNCTIONS
  21.  
  22. function GenerateHitbox(Player, Prop)
  23.     local PrevHitbox = Hitboxes:FindFirstChild(Player.Name)
  24.     if PrevHitbox then
  25.         PrevHitbox:Destroy()
  26.     end
  27.    
  28.     local Root = Player.Character.HumanoidRootPart
  29.    
  30.     local Hitbox = Instance.new("Part")
  31.     Hitbox.Name = Player.Name
  32.     Hitbox.Transparency = 1
  33.     Hitbox.CanCollide = false
  34.     Hitbox.Size = Prop.Size + Vector3.new(2, 2, 2)
  35.    
  36.     local Weld = Instance.new("Motor6D")
  37.     Weld.Part0 = Prop
  38.     Weld.Part1 = Hitbox
  39.    
  40.     Weld.Parent = Hitbox
  41.     local RootPos = Root.CFrame
  42.    
  43.     Hitbox.Parent = workspace.Hitboxes
  44.     Root.CFrame = RootPos
  45.    
  46.     Hitbox:SetNetworkOwner(Player)
  47. end
  48.  
  49. function ChangeLegCollision(Character, Leg)
  50.     PhysicsService:SetPartCollisionGroup(Character[Leg.."Foot"], "Legs")
  51.     PhysicsService:SetPartCollisionGroup(Character[Leg.."LowerLeg"], "Legs")
  52.     PhysicsService:SetPartCollisionGroup(Character[Leg.."UpperLeg"], "Legs")
  53. end
  54.  
  55. return function(Player, Prop)
  56.     local Session = _G.GetSessionData(Player)
  57.     local Character = Player.Character
  58.     local Root = Character.HumanoidRootPart
  59.    
  60.     Session.Props = Session.Props + 1
  61.     Session["Unique Props"][Prop] = true
  62.    
  63.     local PreviousProp = workspace.Props:FindFirstChild(Player.Name)
  64.    
  65.     if PreviousProp then
  66.         PreviousProp:Destroy()
  67.     else
  68.         CollectionService:AddTag(Character, "Prop")
  69.         ChangeLegCollision(Character, "Left")
  70.         ChangeLegCollision(Character, "Right")
  71.         for _, Object in pairs(Character:GetDescendants()) do
  72.             if Object:IsA("BasePart") then
  73.                 Object.Transparency = 1
  74.             end
  75.         end
  76.         Character.HumanoidRootPart.Transparency = 1
  77.         Character.Head.face.Parent = Character
  78.         Character.Humanoid.HipHeight = .3
  79.     end
  80.    
  81.     local String = Instance.new("StringValue")
  82.     String.Name = "PropName"
  83.     String.Value = Prop
  84.    
  85.     local Prop = Props[Prop]:Clone()
  86.    
  87.     local Weld = Instance.new("Motor6D")
  88.     Prop.Name = Player.Name
  89.     Weld.Part0 = Character.HumanoidRootPart
  90.     Weld.Part1 = Prop
  91.     Weld.C0 = CFrame.new(0, (-1.3 + Prop.Size.Y/2), 0)
  92.     Weld.Parent = Prop
  93.     String.Parent = Prop
  94.     Prop.Parent = workspace.Props
  95.    
  96.    
  97.     Prop:SetNetworkOwner(Player)
  98.    
  99.     GenerateHitbox(Player, Prop)
  100.    
  101.     CollectionService:AddTag(Prop, "Prop")
  102.     PhysicsService:SetPartCollisionGroup(Prop, "Props")
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement