Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LimbDamager = {}
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local CastVisualizer = require(ReplicatedStorage.Packages.CastVisuals)
- local BloodEffects = require(ReplicatedStorage.Game.Modules.BloodEffects)
- local Valid_Limbs = require(ReplicatedStorage.Game.Data.BodyHealthValues)
- local function QuickCheck(BodyPart: BasePart)
- if BodyPart:IsA("BasePart") then
- for _, Limb in Valid_Limbs do
- if BodyPart.Name == Limb.Name then
- return Limb
- end
- end
- end
- end
- local function QuickCheck2(BodyPart: BasePart)
- for _, Limb in Valid_Limbs do
- if BodyPart == Limb.Name then
- return Limb
- end
- end
- end
- local function ApplyVelocity(Character: Model,PartApplying,Amount,Dir,NewDir,Limits)
- local Velocity = Instance.new("LinearVelocity", Character.HumanoidRootPart)
- Velocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
- Velocity.MaxAxesForce = Vector3.new(100000,100000,100000)
- local Att0 = Instance.new("Attachment", Character.HumanoidRootPart)
- Velocity.Attachment0 = Att0
- Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
- Velocity.VectorVelocity = (NewDir*Limits)*Amount
- game.Debris:AddItem(Velocity,0.2)
- game.Debris:AddItem(Att0,0.2)
- end
- function LimbDamager.FindLimb(OriginPart: BasePart,Distance,Face,Velocity,Direction,Duration,Damage,IgnoreTable)
- local Rayparams = RaycastParams.new()
- Rayparams.FilterType = Enum.RaycastFilterType.Exclude
- Rayparams.FilterDescendantsInstances = IgnoreTable or {}
- local Direction = OriginPart.CFrame.LookVector * Distance
- local Result = workspace:Shapecast(OriginPart,Direction*Face,Rayparams)
- local CurrentVelocity = OriginPart.AssemblyLinearVelocity.Magnitude
- if Result and Result.Instance then
- if QuickCheck(Result.Instance) then
- local RagdollBool = Result.Instance.Parent:FindFirstChild("Ragdoll")
- if RagdollBool.Value ~= true then
- RagdollBool.Value = true
- local DamageMulti = 0
- ApplyVelocity(Result.Instance.Parent,OriginPart,Velocity,nil,Direction,Face)
- if Velocity < 0 then
- DamageMulti = (Velocity*-1)*0.05
- else
- DamageMulti = Velocity*0.05
- end
- LimbDamager.DamageLimb(Result.Instance.Parent,Result.Instance.Name,Damage*DamageMulti)
- task.spawn(function()
- task.wait(Duration)
- RagdollBool.Value = false
- end)
- end
- return Result.Instance, CurrentVelocity
- else
- return false
- end
- else
- return false
- end
- end
- function LimbDamager.DamageLimb(Character: Model,LimbSelected: string,Damage)
- local Player
- if Players:GetPlayerFromCharacter(Character) then
- Player = Players:GetPlayerFromCharacter(Character)
- end
- local Selected = QuickCheck2(LimbSelected)
- local OriginalHealth = Character:GetAttribute(Selected.Name2)
- local NewHealth = OriginalHealth - Damage
- if Damage > 5 then
- BloodEffects.StartEffects(Character[LimbSelected],Character)
- end
- print(NewHealth)
- print(OriginalHealth)
- print(Damage)
- if NewHealth < 0 then
- NewHealth = 0
- end
- if NewHealth == 0 then
- if not Character:FindFirstChild("Dead_"..LimbSelected) then
- local RealLimb = Character[LimbSelected]:: BasePart
- if RealLimb:FindFirstChild("Mesh") then
- RealLimb.Mesh:Destroy()
- end
- local Replacement = ReplicatedStorage.Game.Assets.Gore.Skeleton[LimbSelected]:Clone():: BasePart
- Replacement.CanCollide = false
- Replacement.Anchored = false
- Replacement.Parent = Character
- Replacement.CFrame = RealLimb.CFrame
- RealLimb.Name = "Dead_"..RealLimb.Name
- RealLimb.Transparency = 1
- for _, Accecory in Character:GetChildren() do
- if Accecory:IsA("Accessory") then
- if Accecory.AccessoryType == Enum.AccessoryType.Hat and LimbSelected == "Head" then
- Accecory:Destroy()
- end
- end
- end
- for _, obj in RealLimb:GetChildren() do
- if not RealLimb:FindFirstChild(obj.Name) then
- obj.Parent = Replacement
- else
- obj:Destroy()
- end
- end
- if LimbSelected == "Torso" then
- local NewWeld = Instance.new("Weld")
- NewWeld.Parent = Character.HumanoidRootPart
- NewWeld.Part0 = Character.HumanoidRootPart
- NewWeld.Part1 = Replacement
- end
- local Torso = Character.Torso:: BasePart
- local Humanoid = Character.Humanoid:: Humanoid
- Humanoid.RequiresNeck = false
- for _, Motor6d in Character:GetDescendants() do
- if Motor6d:IsA("Motor6D") then
- if Motor6d.Part1 == RealLimb then
- Motor6d.Part1 = Replacement
- end
- end
- end
- end
- end
- print(NewHealth)
- Character:SetAttribute(Selected.Name2,NewHealth)
- local TotalHealth = 0
- for _, Limb in Valid_Limbs do
- local LimbHealth = Character:GetAttribute(Limb.Name2)
- TotalHealth += LimbHealth
- if Player then
- ReplicatedStorage.Game.RemoteEvents.LimbHealthChange:FireClient(Player,Limb)
- end
- end
- if TotalHealth <= 0 then
- Character.Humanoid.Health = 0
- end
- end
- return LimbDamager
Advertisement
Add Comment
Please, Sign In to add comment