local v=400 local B=game:GetService("\087\111\114\107\115\112\097\099\101")local Q=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local I=game:GetService("\082\117\110\083\101\114\118\105\099\101")local u=game:GetService("\068\101\098\114\105\115")local U=Q:WaitForChild("\077\105\115\099\115")local L=Q:WaitForChild("\082\101\109\111\116\101\115")local Y=Q:WaitForChild("\069\118\101\110\116\115")local V=Q:WaitForChild("\077\111\100\117\108\101\115")local R=require(V.Utilities)local m=R.Thread local T=U.Gibs local f=U.GibsR15 local O=U.Skeleton local G=U.SkeletonR15 local x=B.CurrentCamera local b=Y.gib local o=L.VisualizeGore local d={}local k={"\100\097\109\097\103\101\100\046\104\101\097\100\046\049","\100\097\109\097\103\101\100\046\104\101\097\100\046\050";"\100\097\109\097\103\101\100\046\104\101\097\100\046\051"}local A={Head={"\100\097\109\097\103\101\100\046\104\101\097\100\046\098\111\110\101\046\049","\100\097\109\097\103\101\100\046\104\101\097\100\046\098\111\110\101\046\050"};["\082\105\103\104\116 \065\114\109"]={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\097\114\109\046\049";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\097\114\109\046\050";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\097\114\109\046\102\108\101\115\104\046\049","\100\097\109\097\103\101\100\046\114\105\103\104\116\046\097\114\109\046\102\108\101\115\104\046\050"},["\076\101\102\116 \065\114\109"]={"\100\097\109\097\103\101\100\046\108\101\102\116\046\097\114\109\046\049","\100\097\109\097\103\101\100\046\108\101\102\116\046\097\114\109\046\050";"\100\097\109\097\103\101\100\046\108\101\102\116\046\097\114\109\046\102\108\101\115\104\046\049","\100\097\109\097\103\101\100\046\108\101\102\116\046\097\114\109\046\102\108\101\115\104\046\050"},["\082\105\103\104\116 \076\101\103"]={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\101\103\046\049";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\101\103\046\050";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\101\103\046\102\108\101\115\104\046\049","\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\101\103\046\102\108\101\115\104\046\050"},["\076\101\102\116 \076\101\103"]={"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\101\103\046\049","\100\097\109\097\103\101\100\046\108\101\102\116\046\108\101\103\046\050";"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\101\103\046\102\108\101\115\104\046\049";"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\101\103\046\102\108\101\115\104\046\050"},Torso={"\100\097\109\097\103\101\100\046\116\111\114\115\111";"\100\097\109\097\103\101\100\046\116\111\114\115\111\046\102\108\101\115\104";"\100\097\109\097\103\101\100\046\116\111\114\115\111\046\098\111\110\101"}}local l={Head={"\100\097\109\097\103\101\100\046\104\101\097\100\046\098\111\110\101\046\049","\100\097\109\097\103\101\100\046\104\101\097\100\046\098\111\110\101\046\050"};RightUpperArm={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\117\112\112\101\114\046\097\114\109","\100\097\109\097\103\101\100\046\114\105\103\104\116\046\117\112\112\101\114\046\097\114\109\046\098\111\110\101"};RightLowerArm={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\111\119\101\114\046\097\114\109";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\111\119\101\114\046\097\114\109\046\102\108\101\115\104"},RightHand={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\104\097\110\100"};LeftUpperArm={"\100\097\109\097\103\101\100\046\108\101\102\116\046\117\112\112\101\114\046\097\114\109";"\100\097\109\097\103\101\100\046\108\101\102\116\046\117\112\112\101\114\046\097\114\109\046\098\111\110\101"};LeftLowerArm={"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\111\119\101\114\046\097\114\109","\100\097\109\097\103\101\100\046\108\101\102\116\046\108\111\119\101\114\046\097\114\109\046\102\108\101\115\104"};LeftHand={"\100\097\109\097\103\101\100\046\108\101\102\116\046\104\097\110\100"};RightUpperLeg={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\117\112\112\101\114\046\108\101\103";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\117\112\112\101\114\046\108\101\103\046\102\108\101\115\104"};RightLowerLeg={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\111\119\101\114\046\108\101\103";"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\108\111\119\101\114\046\108\101\103\046\102\108\101\115\104"},RightFoot={"\100\097\109\097\103\101\100\046\114\105\103\104\116\046\102\111\111\116"};LeftUpperLeg={"\100\097\109\097\103\101\100\046\108\101\102\116\046\117\112\112\101\114\046\108\101\103","\100\097\109\097\103\101\100\046\108\101\102\116\046\117\112\112\101\114\046\108\101\103\046\102\108\101\115\104"};LeftLowerLeg={"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\111\119\101\114\046\108\101\103";"\100\097\109\097\103\101\100\046\108\101\102\116\046\108\111\119\101\114\046\108\101\103\046\102\108\101\115\104"},LeftFoot={"\100\097\109\097\103\101\100\046\108\101\102\116\046\102\111\111\116"},UpperTorso={"\100\097\109\097\103\101\100\046\117\112\112\101\114\046\116\111\114\115\111","\100\097\109\097\103\101\100\046\117\112\112\101\114\046\116\111\114\115\111\046\098\111\110\101"};LowerTorso={"\100\097\109\097\103\101\100\046\108\111\119\101\114\046\116\111\114\115\111","\100\097\109\097\103\101\100\046\108\111\119\101\114\046\116\111\114\115\111\046\102\108\101\115\104"}}local a={Head={"\104\101\097\100"};["\082\105\103\104\116 \065\114\109"]={"\114\105\103\104\116\046\097\114\109"},["\076\101\102\116 \065\114\109"]={"\108\101\102\116\046\097\114\109"};["\082\105\103\104\116 \076\101\103"]={"\114\105\103\104\116\046\108\101\103"};["\076\101\102\116 \076\101\103"]={"\108\101\102\116\046\108\101\103"};Torso={"\116\111\114\115\111"}}local p={Head={"\104\101\097\100"};RightUpperArm={"\114\105\103\104\116\046\117\112\112\101\114\046\097\114\109"};RightLowerArm={"\114\105\103\104\116\046\108\111\119\101\114\046\097\114\109"};RightHand={"\114\105\103\104\116\046\104\097\110\100"},LeftUpperArm={"\108\101\102\116\046\117\112\112\101\114\046\097\114\109"};LeftLowerArm={"\108\101\102\116\046\108\111\119\101\114\046\097\114\109"};LeftHand={"\108\101\102\116\046\104\097\110\100"};RightUpperLeg={"\114\105\103\104\116\046\117\112\112\101\114\046\108\101\103"};RightLowerLeg={"\114\105\103\104\116\046\108\111\119\101\114\046\108\101\103"},RightFoot={"\114\105\103\104\116\046\102\111\111\116"};LeftUpperLeg={"\108\101\102\116\046\117\112\112\101\114\046\108\101\103"};LeftLowerLeg={"\108\101\102\116\046\108\111\119\101\114\046\108\101\103"},LeftFoot={"\108\101\102\116\046\102\111\111\116"},UpperTorso={"\117\112\112\101\114\046\116\111\114\115\111"};LowerTorso={"\108\111\119\101\114\046\116\111\114\115\111"}}function DoOdds(v)if(Random.new()):NextInteger(0,100)<=v then return true end return false end local function X(B,Q,I,U)if Q:FindFirstChild("\084\111\114\115\111")and(B.Transparency~=1 and(not Q:FindFirstChild("\103\105\098\098\101\100")and(B.Position-x.CFrame.p).Magnitude<=v))then B.Transparency=1 local v=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",Q)v.Name="\103\105\098\098\101\100"local L=B:FindFirstChildOfClass("\068\101\099\097\108")if L then L:Destroy()end if B.Name=="\072\101\097\100"then local v=Q:GetChildren()for B=1,#v,1 do if v[B]:IsA("\072\097\116")or v[B]:IsA("\065\099\099\101\115\115\111\114\121")then local I=v[B].Handle:Clone()local u=I:GetChildren()for v=1,#u,1 do if u[v]:IsA("\087\101\108\100")then u[v]:Destroy()end end I.CFrame=v[B].Handle.CFrame I.CanCollide=true I.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)I.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)I.Parent=Q v[B].Handle.Transparency=1 end end end for v,I in pairs(a[B.Name])do local u=O[I]:Clone()u.Anchored=true u.CanCollide=false u.Parent=Q local U=O.rig[B.Name].CFrame:ToObjectSpace(u.CFrame)d[u]=function()return B.CFrame*U end end local Y=Instance.new("\065\116\116\097\099\104\109\101\110\116")Y.CFrame=B.CFrame Y.Parent=workspace.Terrain local V=Instance.new("\083\111\117\110\100",Y)V.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..I.GoreSoundIDs[math.random(1,#I.GoreSoundIDs)]V.PlaybackSpeed=(Random.new()):NextNumber(I.GoreSoundPitchMin,I.GoreSoundPitchMax)V.Volume=I.GoreSoundVolume local function R()local v=U:GetChildren()for B=1,#v,1 do if v[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local Q=1 local I=v[B]:Clone()I.Parent=Y if I:FindFirstChild("\069\109\105\116\067\111\117\110\116")then Q=I.EmitCount.Value end m:Delay(.01,function()I:Emit(Q)u:AddItem(I,I.Lifetime.Max)end)end end V:Play()end m:Spawn(R)u:AddItem(Y,10)end end local function D(B,Q,I,U)if Q:FindFirstChild("\084\111\114\115\111")and(B.Transparency~=1 and(not Q:FindFirstChild("\103\105\098\098\101\100")and(B.Position-x.CFrame.p).Magnitude<=v))then B.Transparency=1 local v=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",Q)v.Name="\103\105\098\098\101\100"local L=B:FindFirstChildOfClass("\068\101\099\097\108")if L then L:Destroy()end if B.Name=="\072\101\097\100"then local v=Q:GetChildren()for B=1,#v,1 do if v[B]:IsA("\072\097\116")or v[B]:IsA("\065\099\099\101\115\115\111\114\121")then local I=v[B].Handle:Clone()local u=I:GetChildren()for v=1,#u,1 do if u[v]:IsA("\087\101\108\100")then u[v]:Destroy()end end I.CFrame=v[B].Handle.CFrame I.CanCollide=true I.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)I.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)I.Parent=Q v[B].Handle.Transparency=1 end end for v,I in pairs(k)do local u=T[I]:Clone()u.Color=B.Color u.CFrame=B.CFrame u.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)u.Velocity=Vector3.new((math.random()-.5)*25,math.random(50,100),(math.random()-.5)*25)u.Parent=Q end end for v,I in pairs(A[B.Name])do local u=T[I]:Clone()u.Anchored=true u.CanCollide=false if not(u.Name:match("\102\108\101\115\104")or u.Name:match("\098\111\110\101"))then u.Color=B.Color if not u.Name:match("\104\101\097\100")then if u.Name:match("\108\101\103")or u.Name:match("\102\111\111\116")then if Q:FindFirstChildOfClass("\080\097\110\116\115")then u.TextureID=(Q:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end else if u.Name:match("\116\111\114\115\111")then if Q:FindFirstChildOfClass("\083\104\105\114\116")then u.TextureID=(Q:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate else if Q:FindFirstChildOfClass("\080\097\110\116\115")then u.TextureID=(Q:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end end else if Q:FindFirstChildOfClass("\083\104\105\114\116")then u.TextureID=(Q:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate end end end end end u.Parent=Q local U=T.rig[B.Name].CFrame:ToObjectSpace(u.CFrame)d[u]=function()return B.CFrame*U end end local Y=Instance.new("\065\116\116\097\099\104\109\101\110\116")Y.CFrame=B.CFrame Y.Parent=workspace.Terrain local V=Instance.new("\083\111\117\110\100",Y)V.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..I.GoreSoundIDs[math.random(1,#I.GoreSoundIDs)]V.PlaybackSpeed=(Random.new()):NextNumber(I.GoreSoundPitchMin,I.GoreSoundPitchMax)V.Volume=I.GoreSoundVolume local function R()local v=U:GetChildren()for B=1,#v,1 do if v[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local Q=1 local I=v[B]:Clone()I.Parent=Y if I:FindFirstChild("\069\109\105\116\067\111\117\110\116")then Q=I.EmitCount.Value end m:Delay(.01,function()I:Emit(Q)u:AddItem(I,I.Lifetime.Max)end)end end V:Play()end m:Spawn(R)u:AddItem(Y,10)end end local function K(B,Q,I,U)if Q:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")and(B.Transparency~=1 and(not Q:FindFirstChild("\103\105\098\098\101\100")and(B.Position-x.CFrame.p).Magnitude<=v))then B.Transparency=1 local v=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",Q)v.Name="\103\105\098\098\101\100"local L=B:FindFirstChildOfClass("\068\101\099\097\108")if L then L:Destroy()end if B.Name=="\072\101\097\100"then local v=Q:GetChildren()for B=1,#v,1 do if v[B]:IsA("\072\097\116")or v[B]:IsA("\065\099\099\101\115\115\111\114\121")then local I=v[B].Handle:Clone()local u=I:GetChildren()for v=1,#u,1 do if u[v]:IsA("\087\101\108\100")then u[v]:Destroy()end end I.CFrame=v[B].Handle.CFrame I.CanCollide=true I.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)I.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)I.Parent=Q v[B].Handle.Transparency=1 end end end for v,I in pairs(p[B.Name])do local u=G[I]:Clone()u.Anchored=true u.CanCollide=false u.Parent=Q local U=G.rig[B.Name].CFrame:ToObjectSpace(u.CFrame)d[u]=function()return B.CFrame*U end end local Y=Instance.new("\065\116\116\097\099\104\109\101\110\116")Y.CFrame=B.CFrame Y.Parent=workspace.Terrain local V=Instance.new("\083\111\117\110\100",Y)V.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..I.GoreSoundIDs[math.random(1,#I.GoreSoundIDs)]V.PlaybackSpeed=(Random.new()):NextNumber(I.GoreSoundPitchMin,I.GoreSoundPitchMax)V.Volume=I.GoreSoundVolume local function R()local v=U:GetChildren()for B=1,#v,1 do if v[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local Q=1 local I=v[B]:Clone()I.Parent=Y if I:FindFirstChild("\069\109\105\116\067\111\117\110\116")then Q=I.EmitCount.Value end m:Delay(.01,function()I:Emit(Q)u:AddItem(I,I.Lifetime.Max)end)end end V:Play()end m:Spawn(R)u:AddItem(Y,10)end end local function h(B,Q,I,U)if Q:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")and(B.Transparency~=1 and(not Q:FindFirstChild("\103\105\098\098\101\100")and(B.Position-x.CFrame.p).Magnitude<=v))then B.Transparency=1 local v=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",Q)v.Name="\103\105\098\098\101\100"local L=B:FindFirstChildOfClass("\068\101\099\097\108")if L then L:Destroy()end if B.Name=="\072\101\097\100"then local v=Q:GetChildren()for B=1,#v,1 do if v[B]:IsA("\072\097\116")or v[B]:IsA("\065\099\099\101\115\115\111\114\121")then local I=v[B].Handle:Clone()local u=I:GetChildren()for v=1,#u,1 do if u[v]:IsA("\087\101\108\100")then u[v]:Destroy()end end I.CFrame=v[B].Handle.CFrame I.CanCollide=true I.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)I.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)I.Parent=Q v[B].Handle.Transparency=1 end end for v,I in pairs(k)do local u=T[I]:Clone()u.Color=B.Color u.CFrame=B.CFrame u.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)u.Velocity=Vector3.new((math.random()-.5)*25,math.random(50,100),(math.random()-.5)*25)u.Parent=Q end end for v,I in pairs(l[B.Name])do local u=f[I]:Clone()u.Anchored=true u.CanCollide=false if not(u.Name:match("\102\108\101\115\104")or u.Name:match("\098\111\110\101"))then u.Color=B.Color if not u.Name:match("\104\101\097\100")then if u.Name:match("\108\101\103")or u.Name:match("\102\111\111\116")then if Q:FindFirstChildOfClass("\080\097\110\116\115")then u.TextureID=(Q:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end else if u.Name:match("\116\111\114\115\111")then if Q:FindFirstChildOfClass("\083\104\105\114\116")then u.TextureID=(Q:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate else if Q:FindFirstChildOfClass("\080\097\110\116\115")then u.TextureID=(Q:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end end else if Q:FindFirstChildOfClass("\083\104\105\114\116")then u.TextureID=(Q:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate end end end end end u.Parent=Q local U=f.rig[B.Name].CFrame:ToObjectSpace(u.CFrame)d[u]=function()return B.CFrame*U end end local Y=Instance.new("\065\116\116\097\099\104\109\101\110\116")Y.CFrame=B.CFrame Y.Parent=workspace.Terrain local V=Instance.new("\083\111\117\110\100",Y)V.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..I.GoreSoundIDs[math.random(1,#I.GoreSoundIDs)]V.PlaybackSpeed=(Random.new()):NextNumber(I.GoreSoundPitchMin,I.GoreSoundPitchMax)V.Volume=I.GoreSoundVolume local function R()local v=U:GetChildren()for B=1,#v,1 do if v[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local Q=1 local I=v[B]:Clone()I.Parent=Y if I:FindFirstChild("\069\109\105\116\067\111\117\110\116")then Q=I.EmitCount.Value end m:Delay(.01,function()I:Emit(Q)u:AddItem(I,I.Lifetime.Max)end)end end V:Play()end m:Spawn(R)u:AddItem(Y,10)end end local function P(v,B,Q,I)if Q.GoreEffectEnabled then if B:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")then if(B:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")).RigType==Enum.HumanoidRigType.R6 then if DoOdds(Q.FullyGibbedLimbChance)then X(v,B,Q,I)else D(v,B,Q,I)end else if DoOdds(Q.FullyGibbedLimbChance)then K(v,B,Q,I)else h(v,B,Q,I)end end end end end b.Event:Connect(P)o.OnClientEvent:Connect(P)I.RenderStepped:Connect(function(v)for v,B in next,d do v.CFrame=B()end end)

local RenderDistance = 400

local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")

local Miscs = ReplicatedStorage:WaitForChild("Miscs")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Events = ReplicatedStorage:WaitForChild("Events")
local Modules = ReplicatedStorage:WaitForChild("Modules")

local Utilities = require(Modules.Utilities)
local Thread = Utilities.Thread

local Gibs = Miscs.Gibs
local GibsR15 = Miscs.GibsR15
local Skeleton = Miscs.Skeleton
local SkeletonR15 = Miscs.SkeletonR15

local Camera = Workspace.CurrentCamera
local Gib = Events.gib
local VisualizeGore = Remotes.VisualizeGore

local Joints = {}

local DamagedHeadParts = {"damaged.head.1", "damaged.head.2", "damaged.head.3"}

local Gore = {
	["Head"] = {"damaged.head.bone.1", "damaged.head.bone.2"},
	["Right Arm"] = {"damaged.right.arm.1", "damaged.right.arm.2", "damaged.right.arm.flesh.1", "damaged.right.arm.flesh.2"},
	["Left Arm"] = {"damaged.left.arm.1", "damaged.left.arm.2", "damaged.left.arm.flesh.1", "damaged.left.arm.flesh.2"},
	["Right Leg"] = {"damaged.right.leg.1", "damaged.right.leg.2", "damaged.right.leg.flesh.1", "damaged.right.leg.flesh.2"},
	["Left Leg"] = {"damaged.left.leg.1", "damaged.left.leg.2", "damaged.left.leg.flesh.1", "damaged.left.leg.flesh.2"},
	["Torso"] = {"damaged.torso", "damaged.torso.flesh", "damaged.torso.bone"},
}

local GoreR15 = {
	["Head"] = {"damaged.head.bone.1", "damaged.head.bone.2"},
	["RightUpperArm"] = {"damaged.right.upper.arm", "damaged.right.upper.arm.bone"},
	["RightLowerArm"] = {"damaged.right.lower.arm", "damaged.right.lower.arm.flesh"},
	["RightHand"] = {"damaged.right.hand"},
	["LeftUpperArm"] = {"damaged.left.upper.arm", "damaged.left.upper.arm.bone"},
	["LeftLowerArm"] = {"damaged.left.lower.arm", "damaged.left.lower.arm.flesh"},
	["LeftHand"] = {"damaged.left.hand"},
	["RightUpperLeg"] = {"damaged.right.upper.leg", "damaged.right.upper.leg.flesh"},
	["RightLowerLeg"] = {"damaged.right.lower.leg", "damaged.right.lower.leg.flesh"},
	["RightFoot"] = {"damaged.right.foot"},
	["LeftUpperLeg"] = {"damaged.left.upper.leg", "damaged.left.upper.leg.flesh"},
	["LeftLowerLeg"] = {"damaged.left.lower.leg", "damaged.left.lower.leg.flesh"},
	["LeftFoot"] = {"damaged.left.foot"},
	["UpperTorso"] = {"damaged.upper.torso", "damaged.upper.torso.bone"},
	["LowerTorso"] = {"damaged.lower.torso", "damaged.lower.torso.flesh"},
}

local Bones = {
	["Head"] = {"head"},
	["Right Arm"] = {"right.arm"},
	["Left Arm"] = {"left.arm"},
	["Right Leg"] = {"right.leg"},
	["Left Leg"] = {"left.leg"},
	["Torso"] = {"torso"},
}

local BonesR15 = {
	["Head"] = {"head"},
	["RightUpperArm"] = {"right.upper.arm"},
	["RightLowerArm"] = {"right.lower.arm"},
	["RightHand"] = {"right.hand"},
	["LeftUpperArm"] = {"left.upper.arm"},
	["LeftLowerArm"] = {"left.lower.arm"},
	["LeftHand"] = {"left.hand"},
	["RightUpperLeg"] = {"right.upper.leg"},
	["RightLowerLeg"] = {"right.lower.leg"},
	["RightFoot"] = {"right.foot"},
	["LeftUpperLeg"] = {"left.upper.leg"},
	["LeftLowerLeg"] = {"left.lower.leg"},
	["LeftFoot"] = {"left.foot"},
	["UpperTorso"] = {"upper.torso"},
	["LowerTorso"] = {"lower.torso"},
}

function DoOdds(Chances)
	if Random.new():NextInteger(0, 100) <= Chances then
		return true
	end
	return false
end

local function FullR6Gib(Joint, Ragdoll, ClientModule, GoreEffect)
	if Ragdoll:FindFirstChild("Torso") and Joint.Transparency ~= 1 and not Ragdoll:FindFirstChild("gibbed") and (Joint.Position - Camera.CFrame.p).Magnitude <= RenderDistance then	
	    Joint.Transparency = 1
	    local Tag = Instance.new("StringValue", Ragdoll)
	    Tag.Name = "gibbed"
				
	    local Decal = Joint:FindFirstChildOfClass("Decal") 
	    if Decal then
		    Decal:Destroy()
	    end

		if Joint.Name == "Head" then
			local parts = Ragdoll:GetChildren()
			for i = 1, #parts do
				if parts[i]:IsA("Hat") or parts[i]:IsA("Accessory") then
					local handle = parts[i].Handle:Clone()
					local children = handle:GetChildren()
					for i = 1, #children do
						if children[i]:IsA("Weld") then
							children[i]:Destroy()
						end
					end
					handle.CFrame = parts[i].Handle.CFrame
					handle.CanCollide = true
				    handle.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
					handle.Velocity = Vector3.new(
						(math.random() - 0.5) * 25,
						math.random(25, 50),
						(math.random() - 0.5) * 25
					)
					handle.Parent = Ragdoll
					parts[i].Handle.Transparency = 1
				end
			end
		end

		for _, Limb in pairs(Bones[Joint.Name]) do
			local limb = Skeleton[Limb]:Clone()
		    limb.Anchored = true
		    limb.CanCollide = false
		    limb.Parent = Ragdoll
		    local offset = Skeleton.rig[Joint.Name].CFrame:ToObjectSpace(limb.CFrame)
		    Joints[limb] = function() return Joint.CFrame * offset end
		end
				
		local Attachment = Instance.new("Attachment")
		Attachment.CFrame = Joint.CFrame
		Attachment.Parent = workspace.Terrain
		local Sound = Instance.new("Sound",Attachment)
		Sound.SoundId = "rbxassetid://"..ClientModule.GoreSoundIDs[math.random(1, #ClientModule.GoreSoundIDs)]
		Sound.PlaybackSpeed = Random.new():NextNumber(ClientModule.GoreSoundPitchMin, ClientModule.GoreSoundPitchMax)
		Sound.Volume = ClientModule.GoreSoundVolume
					
		local function spawner()
		    local C = GoreEffect:GetChildren()
		    for i = 1, #C do
		        if C[i].className == "ParticleEmitter" then
		            local count = 1
		            local Particle = C[i]:Clone()
		            Particle.Parent = Attachment
		            if Particle:FindFirstChild("EmitCount") then
		                count = Particle.EmitCount.Value
		            end
		            Thread:Delay(0.01, function()
		                Particle:Emit(count)
		               	Debris:AddItem(Particle, Particle.Lifetime.Max)
		            end)
		        end
		    end
		    Sound:Play()
		end
				
		Thread:Spawn(spawner)
		Debris:AddItem(Attachment, 10)	
	end
end

local function R6Gib(Joint, Ragdoll, ClientModule, GoreEffect)
	if Ragdoll:FindFirstChild("Torso") and Joint.Transparency ~= 1 and not Ragdoll:FindFirstChild("gibbed") and (Joint.Position - Camera.CFrame.p).Magnitude <= RenderDistance then	
	    Joint.Transparency = 1
	    local Tag = Instance.new("StringValue", Ragdoll)
	    Tag.Name = "gibbed"
				
	    local Decal = Joint:FindFirstChildOfClass("Decal") 
	    if Decal then
		    Decal:Destroy()
	    end

		if Joint.Name == "Head" then
			local parts = Ragdoll:GetChildren()
			for i = 1, #parts do
				if parts[i]:IsA("Hat") or parts[i]:IsA("Accessory") then
					local handle = parts[i].Handle:Clone()
					local children = handle:GetChildren()
					for i = 1, #children do
						if children[i]:IsA("Weld") then
							children[i]:Destroy()
						end
					end
					handle.CFrame = parts[i].Handle.CFrame
					handle.CanCollide = true
				    handle.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
					handle.Velocity = Vector3.new(
						(math.random() - 0.5) * 25,
						math.random(25, 50),
						(math.random() - 0.5) * 25
					)
					handle.Parent = Ragdoll
					parts[i].Handle.Transparency = 1
				end
			end
			for _, headPart in pairs(DamagedHeadParts) do
			    local part = Gibs[headPart]:Clone()
				part.Color = Joint.Color
			    part.CFrame = Joint.CFrame
			    part.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
				part.Velocity = Vector3.new(
					(math.random() - 0.5) * 25,
					math.random(50, 100),
					(math.random() - 0.5) * 25
				)
			    part.Parent = Ragdoll
			end
		end

		for _, Limb in pairs(Gore[Joint.Name]) do
			local limb = Gibs[Limb]:Clone()
		    limb.Anchored = true
		    limb.CanCollide = false
		    if not (limb.Name:match("flesh") or limb.Name:match("bone")) then
				limb.Color = Joint.Color
				if not limb.Name:match("head") then
					if limb.Name:match("leg") or limb.Name:match("foot") then
						if Ragdoll:FindFirstChildOfClass("Pants") then
							limb.TextureID = Ragdoll:FindFirstChildOfClass("Pants").PantsTemplate
						end
					else
						if limb.Name:match("torso") then
							if Ragdoll:FindFirstChildOfClass("Shirt") then
								limb.TextureID = Ragdoll:FindFirstChildOfClass("Shirt").ShirtTemplate
							else
								if Ragdoll:FindFirstChildOfClass("Pants") then
									limb.TextureID = Ragdoll:FindFirstChildOfClass("Pants").PantsTemplate
								end
							end
						else
							if Ragdoll:FindFirstChildOfClass("Shirt") then
								limb.TextureID = Ragdoll:FindFirstChildOfClass("Shirt").ShirtTemplate
							end
						end
					end
				end
		    end
		    limb.Parent = Ragdoll
		    local offset = Gibs.rig[Joint.Name].CFrame:ToObjectSpace(limb.CFrame)
		    Joints[limb] = function() return Joint.CFrame * offset end
		end
				
		local Attachment = Instance.new("Attachment")
		Attachment.CFrame = Joint.CFrame
		Attachment.Parent = workspace.Terrain
		local Sound = Instance.new("Sound",Attachment)
		Sound.SoundId = "rbxassetid://"..ClientModule.GoreSoundIDs[math.random(1, #ClientModule.GoreSoundIDs)]
		Sound.PlaybackSpeed = Random.new():NextNumber(ClientModule.GoreSoundPitchMin, ClientModule.GoreSoundPitchMax)
		Sound.Volume = ClientModule.GoreSoundVolume
					
		local function spawner()
		    local C = GoreEffect:GetChildren()
		    for i = 1, #C do
		        if C[i].className == "ParticleEmitter" then
		            local count = 1
		            local Particle = C[i]:Clone()
		            Particle.Parent = Attachment
		            if Particle:FindFirstChild("EmitCount") then
		                count = Particle.EmitCount.Value
		            end
		            Thread:Delay(0.01, function()
		                Particle:Emit(count)
		               	Debris:AddItem(Particle, Particle.Lifetime.Max)
		            end)
		        end
		    end
		    Sound:Play()
		end
				
		Thread:Spawn(spawner)
		Debris:AddItem(Attachment, 10)	
	end
end

local function FullR15Gib(Joint, Ragdoll, ClientModule, GoreEffect)
	if Ragdoll:FindFirstChild("UpperTorso") and Joint.Transparency ~= 1 and not Ragdoll:FindFirstChild("gibbed") and (Joint.Position - Camera.CFrame.p).Magnitude <= RenderDistance then	
	    Joint.Transparency = 1
	    local Tag = Instance.new("StringValue", Ragdoll)
	    Tag.Name = "gibbed"
				
	    local Decal = Joint:FindFirstChildOfClass("Decal") 
	    if Decal then
		    Decal:Destroy()
	    end

		if Joint.Name == "Head" then
			local parts = Ragdoll:GetChildren()
			for i = 1, #parts do
				if parts[i]:IsA("Hat") or parts[i]:IsA("Accessory") then
					local handle = parts[i].Handle:Clone()
					local children = handle:GetChildren()
					for i = 1, #children do
						if children[i]:IsA("Weld") then
							children[i]:Destroy()
						end
					end
					handle.CFrame = parts[i].Handle.CFrame
					handle.CanCollide = true
				    handle.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
					handle.Velocity = Vector3.new(
						(math.random() - 0.5) * 25,
						math.random(25, 50),
						(math.random() - 0.5) * 25
					)
					handle.Parent = Ragdoll
					parts[i].Handle.Transparency = 1
				end
			end
		end

		for _, Limb in pairs(BonesR15[Joint.Name]) do
			local limb = SkeletonR15[Limb]:Clone()
		    limb.Anchored = true
		    limb.CanCollide = false
		    limb.Parent = Ragdoll
		    local offset = SkeletonR15.rig[Joint.Name].CFrame:ToObjectSpace(limb.CFrame)
		    Joints[limb] = function() return Joint.CFrame * offset end
		end
				
		local Attachment = Instance.new("Attachment")
		Attachment.CFrame = Joint.CFrame
		Attachment.Parent = workspace.Terrain
		local Sound = Instance.new("Sound",Attachment)
		Sound.SoundId = "rbxassetid://"..ClientModule.GoreSoundIDs[math.random(1, #ClientModule.GoreSoundIDs)]
		Sound.PlaybackSpeed = Random.new():NextNumber(ClientModule.GoreSoundPitchMin, ClientModule.GoreSoundPitchMax)
		Sound.Volume = ClientModule.GoreSoundVolume
					
		local function spawner()
		    local C = GoreEffect:GetChildren()
		    for i = 1, #C do
		        if C[i].className == "ParticleEmitter" then
		            local count = 1
		            local Particle = C[i]:Clone()
		            Particle.Parent = Attachment
		            if Particle:FindFirstChild("EmitCount") then
		                count = Particle.EmitCount.Value
		            end
		            Thread:Delay(0.01, function()
		                Particle:Emit(count)
		               	Debris:AddItem(Particle, Particle.Lifetime.Max)
		            end)
		        end
		    end
		    Sound:Play()
		end
				
		Thread:Spawn(spawner)
		Debris:AddItem(Attachment, 10)	
	end
end

local function R15Gib(Joint, Ragdoll, ClientModule, GoreEffect)
	if Ragdoll:FindFirstChild("UpperTorso") and Joint.Transparency ~= 1 and not Ragdoll:FindFirstChild("gibbed") and (Joint.Position - Camera.CFrame.p).Magnitude <= RenderDistance then	
	    Joint.Transparency = 1
	    local Tag = Instance.new("StringValue", Ragdoll)
	    Tag.Name = "gibbed"
				
	    local Decal = Joint:FindFirstChildOfClass("Decal") 
	    if Decal then
		    Decal:Destroy()
	    end

		if Joint.Name == "Head" then
			local parts = Ragdoll:GetChildren()
			for i = 1, #parts do
				if parts[i]:IsA("Hat") or parts[i]:IsA("Accessory") then
					local handle = parts[i].Handle:Clone()
					local children = handle:GetChildren()
					for i = 1, #children do
						if children[i]:IsA("Weld") then
							children[i]:Destroy()
						end
					end
					handle.CFrame = parts[i].Handle.CFrame
					handle.CanCollide = true
				    handle.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
					handle.Velocity = Vector3.new(
						(math.random() - 0.5) * 25,
						math.random(25, 50),
						(math.random() - 0.5) * 25
					)
					handle.Parent = Ragdoll
					parts[i].Handle.Transparency = 1
				end
			end
			for _, headPart in pairs(DamagedHeadParts) do
			    local part = Gibs[headPart]:Clone()
				part.Color = Joint.Color
			    part.CFrame = Joint.CFrame
			    part.RotVelocity = Vector3.new((math.random() - 0.5) * 25, (math.random() - 0.5) * 25, (math.random() - 0.5) * 25)
				part.Velocity = Vector3.new(
					(math.random() - 0.5) * 25,
					math.random(50, 100),
					(math.random() - 0.5) * 25
				)
			    part.Parent = Ragdoll
			end
		end

		for _, Limb in pairs(GoreR15[Joint.Name]) do
			local limb = GibsR15[Limb]:Clone()
		    limb.Anchored = true
		    limb.CanCollide = false
		    if not (limb.Name:match("flesh") or limb.Name:match("bone")) then
				limb.Color = Joint.Color
				if not limb.Name:match("head") then
					if limb.Name:match("leg") or limb.Name:match("foot") then
						if Ragdoll:FindFirstChildOfClass("Pants") then
							limb.TextureID = Ragdoll:FindFirstChildOfClass("Pants").PantsTemplate
						end
					else
						if limb.Name:match("torso") then
							if Ragdoll:FindFirstChildOfClass("Shirt") then
								limb.TextureID = Ragdoll:FindFirstChildOfClass("Shirt").ShirtTemplate
							else
								if Ragdoll:FindFirstChildOfClass("Pants") then
									limb.TextureID = Ragdoll:FindFirstChildOfClass("Pants").PantsTemplate
								end
							end
						else
							if Ragdoll:FindFirstChildOfClass("Shirt") then
								limb.TextureID = Ragdoll:FindFirstChildOfClass("Shirt").ShirtTemplate
							end
						end
					end
				end
		    end
		    limb.Parent = Ragdoll
		    local offset = GibsR15.rig[Joint.Name].CFrame:ToObjectSpace(limb.CFrame)
		    Joints[limb] = function() return Joint.CFrame * offset end
		end
				
		local Attachment = Instance.new("Attachment")
		Attachment.CFrame = Joint.CFrame
		Attachment.Parent = workspace.Terrain
		local Sound = Instance.new("Sound",Attachment)
		Sound.SoundId = "rbxassetid://"..ClientModule.GoreSoundIDs[math.random(1, #ClientModule.GoreSoundIDs)]
		Sound.PlaybackSpeed = Random.new():NextNumber(ClientModule.GoreSoundPitchMin, ClientModule.GoreSoundPitchMax)
		Sound.Volume = ClientModule.GoreSoundVolume
					
		local function spawner()
			local C = GoreEffect:GetChildren()
		    for i = 1, #C do
		        if C[i].className == "ParticleEmitter" then
		            local count = 1
		            local Particle = C[i]:Clone()
		            Particle.Parent = Attachment
		            if Particle:FindFirstChild("EmitCount") then
		                count = Particle.EmitCount.Value
		            end
		            Thread:Delay(0.01, function()
		                Particle:Emit(count)
		               	Debris:AddItem(Particle, Particle.Lifetime.Max)
		            end)
		        end
		    end
		    Sound:Play()
		end
				
		Thread:Spawn(spawner)
		Debris:AddItem(Attachment, 10)	
	end
end

local function GibJoint(Joint, Ragdoll, ClientModule, GoreEffect)
	if ClientModule.GoreEffectEnabled then
		if Ragdoll:FindFirstChildOfClass("Humanoid") then
			if Ragdoll:FindFirstChildOfClass("Humanoid").RigType == Enum.HumanoidRigType.R6 then
				if DoOdds(ClientModule.FullyGibbedLimbChance) then
					FullR6Gib(Joint, Ragdoll, ClientModule, GoreEffect)
				else
					R6Gib(Joint, Ragdoll, ClientModule, GoreEffect)
				end
			else
				if DoOdds(ClientModule.FullyGibbedLimbChance) then
					FullR15Gib(Joint, Ragdoll, ClientModule, GoreEffect)
				else
					R15Gib(Joint, Ragdoll, ClientModule, GoreEffect)
				end
			end
		end
	end
end

Gib.Event:Connect(GibJoint)
VisualizeGore.OnClientEvent:Connect(GibJoint)

RunService.RenderStepped:Connect(function(dt)
	for part, cframe in next, Joints do
		part.CFrame = cframe()
	end
end)
