Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- // SERVICES
- local Players = game:GetService('Players')
- local Debris = game:GetService('Debris')
- -- // VARIABLES
- local Character = script.Parent
- local Player = Players:GetPlayerFromCharacter(Character)
- if not Player:IsA('Player') then print("Something went wrong, this isn't a player? Location: ".. script:GetFullName()) script:Destroy() return end
- local Humanoid = Character:WaitForChild('Humanoid',10)
- if not Humanoid then print("Something went wrong, cannot find Humanoid? Location: ".. script:GetFullName()) script:Destroy() return end
- local UpperTorso = Character:WaitForChild('UpperTorso',10)
- if not UpperTorso then print("Something went wrong, cannot find the UpperTorso? Location: ".. script:GetFullName()) script:Destroy() return end
- local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart',10)
- if not HumanoidRootPart then print("Something went wrong, cannot find the HumanoidRootPart? Location: ".. script:GetFullName()) script:Destroy() return end
- local SendEffect = script:WaitForChild('SendEffect')
- local Carried = false
- local CarryOwner = nil
- local CarryWeld = nil
- local WakeUp = (script.WakeUpAnim.Value and Humanoid:LoadAnimation(script.WakeUp)) or nil
- local RDWELDS,MotorList,GlueList,ColliderList = {},{},{},{}
- function getNearestPlayer( position )
- local Players = game.Players:GetChildren();
- local dist = math.huge;
- local ret = nil;
- for i=1,#Players do
- local Player = Players[i];
- local Character = Player.Character;
- if ( Character ~= nil ) then
- local Root = Character:FindFirstChild("HumanoidRootPart");
- if ( Root ~= nil ) then
- local t = (position - Root.Position).magnitude;
- if ( t < dist ) then
- dist = t;
- ret = Player;
- end
- end
- end
- end
- return ret;
- end
- local RootLimbData = {
- {
- ["WeldTo"] = "LowerTorso",
- ["WeldRoot"] = "HumanoidRootPart",
- ["AttachmentName"] = "Root",
- ["NeedsCollider"] = false,
- ["UpperAngle"] = 10
- },
- {
- ["WeldTo"] = "UpperTorso",
- ["WeldRoot"] = "LowerTorso",
- ["AttachmentName"] = "Waist",
- ["ColliderOffset"] = CFrame.new(0, 0.5, 0),
- ["UpperAngle"] = 0
- },
- {
- ["WeldTo"] = "Head",
- ["WeldRoot"] = "UpperTorso",
- ["AttachmentName"] = "Neck",
- ["ColliderOffset"] = CFrame.new(),
- ["UpperAngle"] = 20
- },
- {
- ["WeldTo"] = "LeftUpperLeg",
- ["WeldRoot"] = "LowerTorso",
- ["AttachmentName"] = "LeftHip",
- ["ColliderOffset"] = CFrame.new(0, -0.5, 0)
- },
- {
- ["WeldTo"] = "RightUpperLeg",
- ["WeldRoot"] = "LowerTorso",
- ["AttachmentName"] = "RightHip",
- ["ColliderOffset"] = CFrame.new(0, -0.5, 0)
- },
- {
- ["WeldTo"] = "RightLowerLeg",
- ["WeldRoot"] = "RightUpperLeg",
- ["AttachmentName"] = "RightKnee",
- ["ColliderOffset"] = CFrame.new(0, -0.5, 0)
- },
- {
- ["WeldTo"] = "LeftLowerLeg",
- ["WeldRoot"] = "LeftUpperLeg",
- ["AttachmentName"] = "LeftKnee",
- ["ColliderOffset"] = CFrame.new(-0.05, -0.5, 0)
- },
- {
- ["WeldTo"] = "RightUpperArm",
- ["WeldRoot"] = "UpperTorso",
- ["AttachmentName"] = "RightShoulder",
- ["ColliderOffset"] = CFrame.new(0.05, 0.45, 0.15),
- },
- {
- ["WeldTo"] = "LeftUpperArm",
- ["WeldRoot"] = "UpperTorso",
- ["AttachmentName"] = "LeftShoulder",
- ["ColliderOffset"] = CFrame.new(0, 0.45, 0.15),
- },
- {
- ["WeldTo"] = "LeftLowerArm",
- ["WeldRoot"] = "LeftUpperArm",
- ["AttachmentName"] = "LeftElbow",
- ["ColliderOffset"] = CFrame.new(0, 0.125, 0),
- ["UpperAngle"] = 10
- },
- {
- ["WeldTo"] = "RightLowerArm",
- ["WeldRoot"] = "RightUpperArm",
- ["AttachmentName"] = "RightElbow",
- ["ColliderOffset"] = CFrame.new(0, 0.125, 0),
- ["UpperAngle"] = 10
- },
- {
- ["WeldTo"] = "RightHand",
- ["WeldRoot"] = "RightLowerArm",
- ["AttachmentName"] = "RightWrist",
- ["ColliderOffset"] = CFrame.new(0, 0.125, 0),
- ["UpperAngle"] = 0
- },
- {
- ["WeldTo"] = "LeftHand",
- ["WeldRoot"] = "LeftLowerArm",
- ["AttachmentName"] = "LeftWrist",
- ["ColliderOffset"] = CFrame.new(0, 0.125, 0),
- ["UpperAngle"] = 0
- },
- {
- ["WeldTo"] = "LeftFoot",
- ["WeldRoot"] = "LeftLowerLeg",
- ["AttachmentName"] = "LeftAnkle",
- ["NeedsCollider"] = false,
- ["UpperAngle"] = 0
- },
- {
- ["WeldTo"] = "RightFoot",
- ["WeldRoot"] = "RightLowerLeg",
- ["AttachmentName"] = "RightAnkle",
- ["NeedsCollider"] = false,
- ["UpperAngle"] = 0
- },
- }
- local Weld = {
- Welder = nil;
- WeldBetween = function(self, Main, x)
- local W = Instance.new("Weld")
- W.Name = "Weld"
- W.Part0 = Main
- W.Part1 = x
- local CJ = CFrame.new(Main.Position)
- local C0 = Main.CFrame:inverse()*CJ
- local C1 = x.CFrame:inverse()*CJ
- W.C0 = C0
- W.C1 = C1
- W.Parent = Main
- table.insert(RDWELDS,#RDWELDS+1,W)
- end;
- WeldTG = function(self, targ, base, unanch, clld)
- for _, prt in pairs(targ:children()) do
- if prt:IsA('BasePart') then
- self:WeldBetween(base,prt)
- prt.Anchored = unanch or false
- prt.CanCollide = clld or false
- if prt.Name == 'Barrel' or prt.Name == 'Handle' then prt.Transparency = 1 end
- end
- end
- end;
- Clear = function(self)
- for _, prt in pairs(RDWELDS) do
- prt.Part1.CanCollide = true;
- prt:Destroy()
- end
- RDWELDS = {}
- end
- }
- SendEffect.OnServerEvent:connect(function(p,action)
- if action == "Carry" then
- if Carried == false and script.Activate.Value then
- if not UpperTorso then return end
- Weld:WeldTG(Character, UpperTorso)
- Carried = true;
- CarryOwner = p.Character
- p.Character.UpperTorso.Anchored = true
- script.CarryOwner.Value = p.Character
- CarryWeld = Instance.new('Weld', script)
- CarryWeld.Part0 = p.Character.UpperTorso
- CarryWeld.Part1 = UpperTorso
- CarryWeld.C0 = CFrame.new(0,0,-2)*CFrame.Angles(math.rad(90),0,math.rad(90))
- p.Character.UpperTorso.Anchored = false
- end
- elseif action == "Drop" then
- Carried = false
- pcall(function() CarryWeld:Destroy() CarryWeld = nil end)
- Weld:Clear()
- CarryOwner = nil
- script.CarryOwner.Value = nil
- elseif action == 'WakeUp' then
- script.Activate.Value = false
- end
- end)
- function deactivate()
- Carried = false
- pcall(function() CarryWeld:Destroy() CarryWeld = nil end)
- Weld:Clear()
- CarryOwner = nil
- script.CarryOwner.Value = nil
- if WakeUp ~= nil then WakeUp:Play() end
- SendEffect:FireClient(Player, "DeactivateAll")
- local posser = UpperTorso.CFrame;
- if UpperTorso ~= nil then
- UpperTorso:SetNetworkOwner(nil);
- HumanoidRootPart.CFrame = CFrame.new(UpperTorso.CFrame.p + Vector3.new(0,3,0));
- HumanoidRootPart.Anchored = true
- end
- for i=1,#MotorList do
- local MotorData = MotorList[i];
- local PartTo = MotorData[1];
- local Motor = MotorData[2];
- Motor.Parent = PartTo;
- end
- for i=1,#GlueList do GlueList[i]:Destroy(); end
- for i=1,#ColliderList do ColliderList[i]:Destroy(); end
- Humanoid.PlatformStand = false;
- HumanoidRootPart.Parent = Character;
- MotorList,GlueList = {},{}
- wait()
- HumanoidRootPart.Anchored = false
- end
- function activate()
- if HumanoidRootPart == 'NF' then return end
- local Position,RagDollModel = HumanoidRootPart.Position, Character
- SendEffect:FireClient(Player, "ActivateBlur")
- Humanoid:UnequipTools()
- Humanoid.PlatformStand = true;
- if Humanoid.Health <= 0 and script.ActivateOnDeath.CloneAndDestroy.Value then
- HumanoidRootPart:Destroy(); HumanoidRootPart = 'NF' -- not found
- Character.Archivable = true;
- RagDollModel = Character:Clone();
- RagDollModel.Name = "Ragdoll";
- for _,v in next, RagDollModel:GetDescendants() do
- if v:IsA("Script") or v:IsA("LocalScript") then
- v:Destroy();
- elseif v:IsA('Humanoid') then
- v.PlatformStand = true;
- v.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None;
- v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff;
- v.Health = 0;
- end
- end
- for _,v in next, Character:GetDescendants() do
- if v:IsA("BasePart") or v:IsA("Accessory") then
- v:Destroy();
- end
- end
- Debris:AddItem(RagDollModel, script.ActivateOnDeath.CloneAndDestroy.Delay.Value);
- RagDollModel.Parent = workspace;
- end
- for i=1,#RootLimbData do
- local limbData = RootLimbData[i];
- local partName = limbData["WeldTo"];
- local weldName = limbData["WeldRoot"];
- local PartTo = RagDollModel:FindFirstChild(partName);
- local WeldTo = RagDollModel:FindFirstChild(weldName);
- if ( PartTo ~= nil and WeldTo ~= nil ) then
- if ( RagDollModel ~= nil ) then
- if script.ApplyRandomVelocity.Value then
- local scale = script.ApplyRandomVelocity.Force.Value;
- local vecX = (math.random()-math.random())*scale;
- local vecY = (math.random()-math.random())*scale;
- local vecZ = (math.random()-math.random())*scale;
- PartTo.Velocity = PartTo.Velocity + Vector3.new(vecX, vecY, vecZ);
- end
- PartTo.Parent = RagDollModel;
- end
- local UpperAngle = limbData["UpperAngle"];
- local Joint = Instance.new("HingeConstraint");
- if ( (UpperAngle ~= nil and UpperAngle == 0) or (script.WeldHead.Value and partName == "Head") ) then
- Joint = Instance.new("HingeConstraint");
- Joint.UpperAngle = 0;
- Joint.LowerAngle = 0;
- end
- Joint.Name = limbData["AttachmentName"];
- Joint.LimitsEnabled = true;
- Joint.Attachment0 = PartTo:FindFirstChild(Joint.Name .. "RigAttachment");
- Joint.Attachment1 = WeldTo:FindFirstChild(Joint.Name .. "RigAttachment");
- Joint.Parent = PartTo;
- GlueList[#GlueList+1] = Joint;
- if ( UpperAngle ~= nil ) then
- Joint.UpperAngle = UpperAngle;
- end
- local Motor = PartTo:FindFirstChildOfClass("Motor6D");
- if ( Motor ~= nil ) then
- if ( Humanoid.Health <= 0 ) then
- Motor:Destroy();
- else
- MotorList[#MotorList+1] = { PartTo, Motor };
- Motor.Parent = nil;
- end
- end
- local needsCollider = limbData["NeedsCollider"];
- if ( needsCollider == nil ) then
- needsCollider = true;
- end
- if ( needsCollider ) then
- local B = Instance.new("Part");
- B.CanCollide = true;
- B.TopSurface = 0;
- B.BottomSurface = 0;
- B.formFactor = "Symmetric";
- B.Size = Vector3.new(0.7, 0.7, 0.7);
- B.Transparency = 1;
- B.BrickColor = BrickColor.Red();
- B.Parent = RagDollModel;
- local W = Instance.new("Weld");
- W.Part0 = PartTo;
- W.Part1 = B;
- W.C0 = limbData["ColliderOffset"];
- W.Parent = PartTo;
- ColliderList[#ColliderList+1] = B;
- end
- end
- end
- if HumanoidRootPart ~= 'NF' then
- HumanoidRootPart.Parent = nil;
- end
- if script.GivePlayerPhysics.Value then
- local PlayerPhysics = Player
- if ( script.GivePlayerPhysics.ForceNearestPlayer.Value ) then
- PlayerPhysics = getNearestPlayer( Position );
- end
- for _,v in next, Character:GetDescendants() do
- if v:IsA("BasePart") then
- v:SetNetworkOwner(PlayerPhysics);
- end
- end
- end
- end
- Humanoid.Died:Connect(function()
- if script.ActivateOnDeath.Value then
- script.Activate.Value = true
- end
- end);
Advertisement
Add Comment
Please, Sign In to add comment