This is the Module Script inside ServerScriptService
local Module = {}
local RE = game.ReplicatedStorage.Ragdoll
local PS = game:GetService("PhysicsService")
local ragDB = false
Module.Ragdoll = function(char,bool)
if ragDB == false then
ragDB = true
local plr = game.Players:GetPlayerFromCharacter(char)
if char.Humanoid.Health~=0 and ((char:FindFirstChild'LowerTorso'and not char.LowerTorso.Root.Enabled)or (char:FindFirstChild'Torso'and not char.Torso.Neck.Enabled)) and not bool then
RE:FireClient(plr,false)
for _,v in pairs(char:GetDescendants()) do
if v:IsA'Motor6D' then
v.Enabled = true
elseif v:IsA'BallSocketConstraint' then
v.Enabled = false
end
end
else
RE:FireClient(plr,true)
for _,v in pairs(char:GetDescendants()) do
if v:IsA'Motor6D'and Module.Check(v.Name)then
v.Enabled = false
elseif v:IsA'BallSocketConstraint' then
v.Enabled = true
elseif v.Name=="Head"then
local b = Instance.new("BodyVelocity",char.Head)
b.Velocity = Vector3.new(math.random(-10,10),0,math.random(-10,10))
wait(0.1)
b:Destroy()
--[[task.spawn(function()
wait(.1)
b:Destroy()
end)--]]
end
end
print("Bef")
task.wait(3)
print("Aft")
RE:FireClient(plr,false)
for _,v in pairs(char:GetDescendants()) do
if v:IsA'Motor6D' then
v.Enabled = true
elseif v:IsA'BallSocketConstraint' then
v.Enabled = false
end
end
end
ragDB = false
end
end
Module.Bot = function(bot)
task.spawn(function()
local H = bot.Humanoid
if bot:FindFirstChild'HumanoidRootPart'and H.Health~=0 and bot:FindFirstChild'LowerTorso' and bot.LowerTorso.Root.Enabled==true then
H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
H:ChangeState(Enum.HumanoidStateType.Ragdoll)
for _,v in pairs(H:GetPlayingAnimationTracks())do v:Stop(0)end
bot.Animate.Disabled = true
for _,v in pairs(bot:GetDescendants()) do
if v:IsA'Motor6D'and Module.Check(v.Name) then
v.Enabled = false
elseif v:IsA'BallSocketConstraint' then
v.Enabled = true
end
end
wait(10)
bot.Animate.Disabled = false
H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
H:ChangeState(Enum.HumanoidStateType.GettingUp)
for _,v in pairs(bot:GetDescendants()) do
if v:IsA'Motor6D' then
v.Enabled = true
elseif v:IsA'BallSocketConstraint' then
v.Enabled = false
end
end
end
end)
end
Module.Check = function(t)
for _,v in pairs({"LeftWrist","RightWrist","LeftAnkle","RightAnkle"}) do
if v == t then return false end
end
return true
end
Module.Joints = function(c)
c.Humanoid.BreakJointsOnDeath = false
c.Humanoid.RequiresNeck = false
for _,v in pairs(c:GetDescendants()) do
if v:IsA("Motor6D")and Module.Check(v.Name)then
local b = Instance.new("BallSocketConstraint",v.Parent)
local a0,a1 = Instance.new("Attachment"),Instance.new("Attachment")
a0.Parent,a1.Parent = v.Part0,v.Part1
b.Attachment0,b.Attachment1 = a0,a1
a0.CFrame,a1.CFrame = v.c0,v.c1
b.LimitsEnabled = true
b.TwistLimitsEnabled = true
b.Enabled = false
elseif v:IsA'BasePart' then
PS:SetPartCollisionGroup(v,"A")
if v.Name == "HumanoidRootPart" then
PS:SetPartCollisionGroup(v,"B")
elseif v.Name=="Head"then
v.CanCollide = true
end
end
end
end
return Module
And this is the script where I call the function
local boulder = script.Parent
local M = require(game.ServerScriptService.Module)
local prevHits = {}
boulder.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not prevHits[hit.Parent.Name] then
table.insert(prevHits, hit.Parent.Name)
M.Ragdoll(hit.Parent, true)
end
end)