i got this pretty long R6 module script from a youtube video for this game im trying to make, but whenever i hit enemies with the bat weapon, their health bar disappears. is this issue happening because of something inside it, or could it be how im using the ragdoll module in my damage script (i can post it if anyone thinks its necessary)? how do i fix it? the issue wasn’t happening before i added the ragdoll and it was just knockback.
module script:
function Module:SetupRagdoll(Character:Model,RagdollOnDeath:boolean)
local PhysicsService = game:GetService("PhysicsService")
local StarterPlayer = game:GetService("StarterPlayer")
local Runservice = game:GetService("RunService")
local BodyPart = {}
local Information = {
IgnoreParts = {"HumanoidRootPart","LowerTorso","UpperTorso","Torso"},
CollisionPartOffset = {["R6"] = 1.8,["R15"] = 2,["Rthro"] = 2.25},
IsRagdolled = false,
Run = nil,
}
local function CreateCollisionPart(Part:Part,Offset:number)
local CollideFolder = Character:FindFirstChild("RagdollCollision")
if not CollideFolder then
CollideFolder = Instance.new("Folder",Character)
CollideFolder.Name = "RagdollCollision"
end
local Collider = Instance.new("Part",Part)
Collider.Size = Part.Size/tonumber(Offset) or 1
Collider.Transparency = 1
Collider.CanQuery = false
Collider.CanTouch = false
Collider.Massless = true
Collider.CFrame = Part.CFrame
Collider.Parent = CollideFolder
if not PhysicsService:IsCollisionGroupRegistered("RagdollCollision") then
PhysicsService:RegisterCollisionGroup("RagdollCollision")
end
Part.CollisionGroup = "RagdollCollision"
PhysicsService:CollisionGroupSetCollidable("Default", "RagdollCollision", false)
local Weld = Instance.new("WeldConstraint",Collider)
Weld.Part0 = Collider
Weld.Part1 = Part
end
if Character == nil then
error("Argument 1 missing")
end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not Humanoid then
error("Character 'Humanoid' missing")
end
for _,Object in pairs(Character:GetChildren()) do
if Object:IsA("BasePart") then
table.insert(BodyPart,Object)
end
end
local temp = {}
local Ragdolling = {
Ragdoll = function(TimeLength:number)
if Information.IsRagdolled == false then
local Boolean,Return = pcall(function()
Information.IsRagdolled = true
for _, Object in pairs(Character:GetDescendants()) do
if Object:IsA("Motor6D") then
local Attachment0, Attachment1 = Instance.new("Attachment"), Instance.new("Attachment")
Attachment0.CFrame = Object.C0
Attachment1.CFrame = Object.C1
Attachment0.Parent = Object.Part0
Attachment1.Parent = Object.Part1
Attachment0.Name = string.format("%s:%s","Ragdoll",Attachment0.ClassName)
Attachment1.Name = string.format("%s:%s","Ragdoll",Attachment1.ClassName)
local BallSocketConstraint = Instance.new("BallSocketConstraint")
BallSocketConstraint.Attachment0 = Attachment0
BallSocketConstraint.Attachment1 = Attachment1
BallSocketConstraint.Parent = Object.Part0
BallSocketConstraint.Name = string.format("%s:%s","Ragdoll",BallSocketConstraint.ClassName)
if not table.find(Information.IgnoreParts,Object.Part1.Name) then
CreateCollisionPart(Object.Part1,Information.CollisionPartOffset[Humanoid.RigType.Name])
end
Object.Enabled = false
end
end
Information.Run = Runservice.Heartbeat:Connect(function()
if Information.IsRagdolled == false then
Information.Run:Disconnect()
end
Humanoid.PlatformStand = Information.IsRagdolled
if StarterPlayer.CharacterUseJumpPower then
if Information.IsRagdolled then
Humanoid.JumpPower = 0
else
Humanoid.JumpPower = StarterPlayer.CharacterJumpPower
end
else
if Information.IsRagdolled then
Humanoid.JumpHeight = 0
else
Humanoid.JumpHeight = StarterPlayer.CharacterJumpHeight
end
end
end)
if typeof(TimeLength) == "number" and TimeLength > 0 then
task.delay(TimeLength,function()
temp.Unragdoll()
end)
end
end)
if not Boolean then
error(Return)
end
end
end;
Unragdoll = function()
if Information.IsRagdolled == true and Humanoid.Health > 0 then
local Boolean,Return = pcall(function()
Information.IsRagdolled = false
local CollideFolder = Character:FindFirstChild("RagdollCollision")
if CollideFolder then
CollideFolder:ClearAllChildren()
end
for _,Object in pairs(Character:GetDescendants()) do
if Object:IsA('Motor6D') then
Object.Enabled = true
end
if Object.Name == string.format("%s:%s","Ragdoll",Object.ClassName) then
Object:Destroy()
end
end
end)
if not Boolean then
error(Return)
end
end
end;
}
if RagdollOnDeath == true then
Humanoid.BreakJointsOnDeath = false
Humanoid.Died:Connect(function()
Ragdolling.Ragdoll()
end)
end
temp = Ragdolling
return Ragdolling
end
return Module