local M=400 local B=game:GetService("\087\111\114\107\115\112\097\099\101")local S=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local q=game:GetService("\082\117\110\083\101\114\118\105\099\101")local Q=game:GetService("\068\101\098\114\105\115")local u=S:WaitForChild("\077\105\115\099\115")local T=S:WaitForChild("\082\101\109\111\116\101\115")local x=S:WaitForChild("\069\118\101\110\116\115")local D=S:WaitForChild("\077\111\100\117\108\101\115")local I=require(D.Utilities)local j=I.Thread local W=u.Gibs local R=u.GibsR15 local c=u.Skeleton local G=u.SkeletonR15 local Y=B.CurrentCamera local y=x.gib local E=T.VisualizeGore local A={}local s={"\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 i={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 H={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 X={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 d={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(M)if(Random.new()):NextInteger(0,100)<=M then return true end return false end local function z(B,S,q)if S:FindFirstChild("\084\111\114\115\111")and(B.Transparency~=1 and(not S:FindFirstChild("\103\105\098\098\101\100")and(B.Position-Y.CFrame.p).Magnitude<=M))then B.Transparency=1 local M=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",S)M.Name="\103\105\098\098\101\100"local u=B:FindFirstChildOfClass("\068\101\099\097\108")if u then u:Destroy()end if B.Name=="\072\101\097\100"then local M=S:GetChildren()for B=1,#M,1 do if M[B]:IsA("\072\097\116")or M[B]:IsA("\065\099\099\101\115\115\111\114\121")then local q=M[B].Handle:Clone()local Q=q:GetChildren()for M=1,#Q,1 do if Q[M]:IsA("\087\101\108\100")then Q[M]:Destroy()end end q.CFrame=M[B].Handle.CFrame q.CanCollide=true q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)q.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)q.Parent=S M[B].Handle.Transparency=1 end end end for M,q in pairs(X[B.Name])do local Q=c[q]:Clone()Q.Anchored=true Q.CanCollide=false Q.Parent=S local u=c.rig[B.Name].CFrame:ToObjectSpace(Q.CFrame)A[Q]=function()return B.CFrame*u end end local T=Instance.new("\065\116\116\097\099\104\109\101\110\116")T.CFrame=B.CFrame T.Parent=workspace.Terrain local x=Instance.new("\083\111\117\110\100",T)x.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..q[2][math.random(1,#q[2])]x.PlaybackSpeed=(Random.new()):NextNumber(q[3],q[4])x.Volume=q[5]local function D()local M=q[6]:GetChildren()for B=1,#M,1 do if M[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local S=1 local q=M[B]:Clone()q.Parent=T if q:FindFirstChild("\069\109\105\116\067\111\117\110\116")then S=q.EmitCount.Value end j:Delay(.01,function()q:Emit(S)Q:AddItem(q,q.Lifetime.Max)end)end end x:Play()end j:Spawn(D)Q:AddItem(T,10)end end local function L(B,S,q)if S:FindFirstChild("\084\111\114\115\111")and(B.Transparency~=1 and(not S:FindFirstChild("\103\105\098\098\101\100")and(B.Position-Y.CFrame.p).Magnitude<=M))then B.Transparency=1 local M=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",S)M.Name="\103\105\098\098\101\100"local u=B:FindFirstChildOfClass("\068\101\099\097\108")if u then u:Destroy()end if B.Name=="\072\101\097\100"then local M=S:GetChildren()for B=1,#M,1 do if M[B]:IsA("\072\097\116")or M[B]:IsA("\065\099\099\101\115\115\111\114\121")then local q=M[B].Handle:Clone()local Q=q:GetChildren()for M=1,#Q,1 do if Q[M]:IsA("\087\101\108\100")then Q[M]:Destroy()end end q.CFrame=M[B].Handle.CFrame q.CanCollide=true q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)q.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)q.Parent=S M[B].Handle.Transparency=1 end end for M,q in pairs(s)do local Q=W[q]:Clone()Q.Color=B.Color Q.CFrame=B.CFrame Q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)Q.Velocity=Vector3.new((math.random()-.5)*25,math.random(50,100),(math.random()-.5)*25)Q.Parent=S end end for M,q in pairs(i[B.Name])do local Q=W[q]:Clone()Q.Anchored=true Q.CanCollide=false if not(Q.Name:match("\102\108\101\115\104")or Q.Name:match("\098\111\110\101"))then Q.Color=B.Color if not Q.Name:match("\104\101\097\100")then if Q.Name:match("\108\101\103")or Q.Name:match("\102\111\111\116")then if S:FindFirstChildOfClass("\080\097\110\116\115")then Q.TextureID=(S:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end else if Q.Name:match("\116\111\114\115\111")then if S:FindFirstChildOfClass("\083\104\105\114\116")then Q.TextureID=(S:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate else if S:FindFirstChildOfClass("\080\097\110\116\115")then Q.TextureID=(S:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end end else if S:FindFirstChildOfClass("\083\104\105\114\116")then Q.TextureID=(S:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate end end end end end Q.Parent=S local u=W.rig[B.Name].CFrame:ToObjectSpace(Q.CFrame)A[Q]=function()return B.CFrame*u end end local T=Instance.new("\065\116\116\097\099\104\109\101\110\116")T.CFrame=B.CFrame T.Parent=workspace.Terrain local x=Instance.new("\083\111\117\110\100",T)x.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..q[2][math.random(1,#q[2])]x.PlaybackSpeed=(Random.new()):NextNumber(q[3],q[4])x.Volume=q[5]local function D()local M=q[6]:GetChildren()for B=1,#M,1 do if M[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local S=1 local q=M[B]:Clone()q.Parent=T if q:FindFirstChild("\069\109\105\116\067\111\117\110\116")then S=q.EmitCount.Value end j:Delay(.01,function()q:Emit(S)Q:AddItem(q,q.Lifetime.Max)end)end end x:Play()end j:Spawn(D)Q:AddItem(T,10)end end local function e(B,S,q)if S:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")and(B.Transparency~=1 and(not S:FindFirstChild("\103\105\098\098\101\100")and(B.Position-Y.CFrame.p).Magnitude<=M))then B.Transparency=1 local M=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",S)M.Name="\103\105\098\098\101\100"local u=B:FindFirstChildOfClass("\068\101\099\097\108")if u then u:Destroy()end if B.Name=="\072\101\097\100"then local M=S:GetChildren()for B=1,#M,1 do if M[B]:IsA("\072\097\116")or M[B]:IsA("\065\099\099\101\115\115\111\114\121")then local q=M[B].Handle:Clone()local Q=q:GetChildren()for M=1,#Q,1 do if Q[M]:IsA("\087\101\108\100")then Q[M]:Destroy()end end q.CFrame=M[B].Handle.CFrame q.CanCollide=true q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)q.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)q.Parent=S M[B].Handle.Transparency=1 end end end for M,q in pairs(d[B.Name])do local Q=G[q]:Clone()Q.Anchored=true Q.CanCollide=false Q.Parent=S local u=G.rig[B.Name].CFrame:ToObjectSpace(Q.CFrame)A[Q]=function()return B.CFrame*u end end local T=Instance.new("\065\116\116\097\099\104\109\101\110\116")T.CFrame=B.CFrame T.Parent=workspace.Terrain local x=Instance.new("\083\111\117\110\100",T)x.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..q[2][math.random(1,#q[2])]x.PlaybackSpeed=(Random.new()):NextNumber(q[3],q[4])x.Volume=q[5]local function D()local M=q[6]:GetChildren()for B=1,#M,1 do if M[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local S=1 local q=M[B]:Clone()q.Parent=T if q:FindFirstChild("\069\109\105\116\067\111\117\110\116")then S=q.EmitCount.Value end j:Delay(.01,function()q:Emit(S)Q:AddItem(q,q.Lifetime.Max)end)end end x:Play()end j:Spawn(D)Q:AddItem(T,10)end end local function V(B,S,q)if S:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")and(B.Transparency~=1 and(not S:FindFirstChild("\103\105\098\098\101\100")and(B.Position-Y.CFrame.p).Magnitude<=M))then B.Transparency=1 local M=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",S)M.Name="\103\105\098\098\101\100"local u=B:FindFirstChildOfClass("\068\101\099\097\108")if u then u:Destroy()end if B.Name=="\072\101\097\100"then local M=S:GetChildren()for B=1,#M,1 do if M[B]:IsA("\072\097\116")or M[B]:IsA("\065\099\099\101\115\115\111\114\121")then local q=M[B].Handle:Clone()local Q=q:GetChildren()for M=1,#Q,1 do if Q[M]:IsA("\087\101\108\100")then Q[M]:Destroy()end end q.CFrame=M[B].Handle.CFrame q.CanCollide=true q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)q.Velocity=Vector3.new((math.random()-.5)*25,math.random(25,50),(math.random()-.5)*25)q.Parent=S M[B].Handle.Transparency=1 end end for M,q in pairs(s)do local Q=W[q]:Clone()Q.Color=B.Color Q.CFrame=B.CFrame Q.RotVelocity=Vector3.new((math.random()-.5)*25,(math.random()-.5)*25,(math.random()-.5)*25)Q.Velocity=Vector3.new((math.random()-.5)*25,math.random(50,100),(math.random()-.5)*25)Q.Parent=S end end for M,q in pairs(H[B.Name])do local Q=R[q]:Clone()Q.Anchored=true Q.CanCollide=false if not(Q.Name:match("\102\108\101\115\104")or Q.Name:match("\098\111\110\101"))then Q.Color=B.Color if not Q.Name:match("\104\101\097\100")then if Q.Name:match("\108\101\103")or Q.Name:match("\102\111\111\116")then if S:FindFirstChildOfClass("\080\097\110\116\115")then Q.TextureID=(S:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end else if Q.Name:match("\116\111\114\115\111")then if S:FindFirstChildOfClass("\083\104\105\114\116")then Q.TextureID=(S:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate else if S:FindFirstChildOfClass("\080\097\110\116\115")then Q.TextureID=(S:FindFirstChildOfClass("\080\097\110\116\115")).PantsTemplate end end else if S:FindFirstChildOfClass("\083\104\105\114\116")then Q.TextureID=(S:FindFirstChildOfClass("\083\104\105\114\116")).ShirtTemplate end end end end end Q.Parent=S local u=R.rig[B.Name].CFrame:ToObjectSpace(Q.CFrame)A[Q]=function()return B.CFrame*u end end local T=Instance.new("\065\116\116\097\099\104\109\101\110\116")T.CFrame=B.CFrame T.Parent=workspace.Terrain local x=Instance.new("\083\111\117\110\100",T)x.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..q[2][math.random(1,#q[2])]x.PlaybackSpeed=(Random.new()):NextNumber(q[3],q[4])x.Volume=q[5]local function D()local M=q[6]:GetChildren()for B=1,#M,1 do if M[B].className=="\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114"then local S=1 local q=M[B]:Clone()q.Parent=T if q:FindFirstChild("\069\109\105\116\067\111\117\110\116")then S=q.EmitCount.Value end j:Delay(.01,function()q:Emit(S)Q:AddItem(q,q.Lifetime.Max)end)end end x:Play()end j:Spawn(D)Q:AddItem(T,10)end end local function k(M,B,S)if S[1]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(S[7])then z(M,B,S)else L(M,B,S)end else if DoOdds(S[7])then e(M,B,S)else V(M,B,S)end end end end end y.Event:Connect(k)E.OnClientEvent:Connect(k)q.RenderStepped:Connect(function(M)for M,B in next,A do M.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, GoreData)
	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://"..GoreData[2][math.random(1, #GoreData[2])]
		Sound.PlaybackSpeed = Random.new():NextNumber(GoreData[3], GoreData[4])
		Sound.Volume = GoreData[5]
					
		local function spawner()
		    local C = GoreData[6]: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, GoreData)
	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://"..GoreData[2][math.random(1, #GoreData[2])]
		Sound.PlaybackSpeed = Random.new():NextNumber(GoreData[3], GoreData[4])
		Sound.Volume = GoreData[5]
					
		local function spawner()
		    local C = GoreData[6]: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, GoreData)
	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://"..GoreData[2][math.random(1, #GoreData[2])]
		Sound.PlaybackSpeed = Random.new():NextNumber(GoreData[3], GoreData[4])
		Sound.Volume = GoreData[5]
					
		local function spawner()
		    local C = GoreData[6]: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, GoreData)
	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://"..GoreData[2][math.random(1,#GoreData[2])]
		Sound.PlaybackSpeed = Random.new():NextNumber(GoreData[3], GoreData[4])
		Sound.Volume = GoreData[5]
					
		local function spawner()
		    local C = GoreData[6]: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, GoreData)
	if GoreData[1] then
		if Ragdoll:FindFirstChildOfClass("Humanoid") then
			if Ragdoll:FindFirstChildOfClass("Humanoid").RigType == Enum.HumanoidRigType.R6 then
				if DoOdds(GoreData[7]) then
					FullR6Gib(Joint, Ragdoll, GoreData)
				else
					R6Gib(Joint, Ragdoll, GoreData)
				end
			else
				if DoOdds(GoreData[7]) then
					FullR15Gib(Joint, Ragdoll, GoreData)
				else
					R15Gib(Joint, Ragdoll, GoreData)
				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)
