You can write your topic however you want, but you need to answer these questions:
What I am currentley trying to do is get my character to ragdoll whenever they die.
But instead they just stifen up like this. Although when I press “r” when I am dead the ragdoll seems to work perfectley fine.
I do set break joints on death to false whenever the character is added. Yet the issue still pervails
CLIENT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local NetworkerClient = require(ReplicatedStorage.Packages.Networker.Client)
local RagdollServiceClient = {}
function RagdollServiceClient.Init(self : RagdollServiceClient)
local stillCount = 0
local fallingCount = 0
local lastVelocity = 0
self.ragdolling = false
self.Networker = NetworkerClient.new("Ragdoll",self)
self.ragdollVelocity = 100
self.rToRagdoll = false
self.isThirdPerson = true
Player.CharacterAdded:Connect(function(character)
Player.PlayerGui.DeathGui.Enabled = false
stillCount = 0
fallingCount = 0
lastVelocity = 0
local humanoid : Humanoid = character.Humanoid
humanoid.Died:Once(function()
self.Networker:fire("RequestRagdoll",true)
end)
end)
ContextActionService:BindAction(
"Ragdoll",
function(action,inputState,inputObject)
if inputState ~= Enum.UserInputState.Begin and inputState ~= nil then
return
end
self.rToRagdoll = not self.rToRagdoll
self.Networker:fire("RequestRagdoll",self.rToRagdoll)
end,
false,
Enum.KeyCode.R
)
RunService.RenderStepped:Connect(function(dt)
if self.ragdolling and fallingCount > 2 then
self.isThirdPerson = false
self:FirstPerson()
elseif self.isThirdPerson == false then
self.isThirdPerson = true
self:ThirdPerson()
end
if self:IsFalling() == true then
self:RequestRagdoll(true)
fallingCount += dt
stillCount = 0
if lastVelocity - self:GetPlayerVelocity() > 100 and self.ragdolling == true then
Player.PlayerGui.DeathGui.Enabled = true
end
lastVelocity = self:GetPlayerVelocity()
return
end
stillCount += dt
if stillCount >= 2 then
self:RequestRagdoll(false)
fallingCount = 0
end
end)
end
function RagdollServiceClient.IsFalling(self : RagdollServiceClient)
return self:GetPlayerVelocity() > self.ragdollVelocity
end
function RagdollServiceClient.GetPlayerVelocity(self : RagdollServiceClient)
local character : Part = Player.Character
if character == nil then
return 0
end
local humanoidRootPart : Part = character.HumanoidRootPart
if humanoidRootPart == nil then
return 0
end
return humanoidRootPart.AssemblyLinearVelocity.Magnitude
end
function RagdollServiceClient.RequestRagdoll(
self : RagdollServiceClient,
ragdoll : boolean
)
if self.ragdolling == ragdoll or self.rToRagdoll == true then
return
end
self.Networker:fire("RequestRagdoll",ragdoll)
end
function RagdollServiceClient.Ragdoll(self : RagdollServiceClient)
local character = Player.Character
local humanoid : Humanoid = character.Humanoid
local humanoidRootPart : Part = character.HumanoidRootPart
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)
humanoid.AutoRotate = false
humanoid.PlatformStand = true
self.ragdolling = true
end
function RagdollServiceClient.UnRagdoll(self : RagdollServiceClient)
local character = Player.Character
local humanoid : Humanoid = character.Humanoid
local humanoidRootPart : Part = character.HumanoidRootPart
if humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
local position = humanoidRootPart.Position
humanoidRootPart.CFrame = CFrame.new(position) * CFrame.Angles(0,humanoidRootPart.Orientation.Y * math.pi/180,0)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running,true)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)
humanoid.PlatformStand = false
humanoid.AutoRotate = true
self.ragdolling= false
end
function RagdollServiceClient.FirstPerson(self : RagdollServiceClient)
local head : Part = Player.Character.Head
head.LocalTransparencyModifier = 1
for _, v in Player.Character:GetChildren() do
if v:IsA("Accessory") then
v.Handle.LocalTransparencyModifier = 1
end
end
Camera:PivotTo(head.CFrame)
end
function RagdollServiceClient.ThirdPerson(self : RagdollServiceClient)
if Player.Character == nil or Player.Character.Head == nil then
return
end
local head : Part = Player.Character.Head
head.LocalTransparencyModifier = 0
for _, v in Player.Character:GetChildren() do
if v:IsA("Accessory") then
v.Handle.LocalTransparencyModifier = 0
end
end
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Player.Character.Humanoid
end
type RagdollServiceClient = typeof(RagdollServiceClient)
return RagdollServiceClient
SERVER
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local NetworkerServer = require(ReplicatedStorage.Packages.Networker.Server)
local ConnectionManager = require(ReplicatedStorage.Packages.MyPackages.ConnectionManager)
local Binder = require(ReplicatedStorage.Packages.MyPackages.Binder)
local RagdollServiceServer = {}
function RagdollServiceServer.Init(self : RagdollServiceServer)
self.Networker = NetworkerServer.new("Ragdoll",self,{
self.RequestRagdoll
})
self.ConnectionManagers = {}
self.CFrameOffsets = require(script.CFrameOffsets)
self.RagdollStates = {}
Players.PlayerAdded:Connect(function(player)
self:SetUpPlayer(player)
end)
Players.PlayerRemoving:Connect(function(player)
self:CleanUpPlayer(player)
end)
end
function RagdollServiceServer.SetUpPlayer(self : RagdollServiceServer,player : Player)
self.ConnectionManagers[player.UserId] = ConnectionManager.new()
self.ConnectionManagers[player.UserId]:AddConnection("Character",player.CharacterAdded:Connect(function(character)
self:SetUpCharacter(character)
self:UnRagdoll(character)
end))
end
function RagdollServiceServer.CleanUpPlayer(self : RagdollServiceServer,player : Player)
self.ConnectionManagers[player.UserId]:CleanUp()
self.RagdollStates[player.UserId] = nil
end
function RagdollServiceServer.SetUpCharacter(self : RagdollServiceServer, character : Model)
local humanoid : Humanoid = character.Humanoid
local player = Players:GetPlayerFromCharacter(character)
humanoid.BreakJointsOnDeath = false
humanoid.RequiresNeck = false
for _, part : Part in character:GetChildren() do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
local collisionPart = Instance.fromExisting(part)
collisionPart.CanCollide = false
collisionPart.Massless = true
collisionPart.Size = Vector3.one
collisionPart.Name = "Collide"
collisionPart.Transparency = 1
collisionPart:ClearAllChildren()
collisionPart.Parent = part
local weld = Instance.new("Weld")
weld.Part0 = part
weld.Part1 = collisionPart
weld.Parent = collisionPart
end
end
end
function RagdollServiceServer.EnableMotor6D(self : RagdollServiceServer, character : Model, enabled : boolean)
for _, motor : Motor6D in character:GetDescendants() do
if motor.Name == "Handle" or motor.Name == "RootJoint" or motor.Name == "Neck" then
continue
end
if motor:IsA("Motor6D") then
motor.Enabled = enabled
end
end
end
function RagdollServiceServer.BuildJoints(self : RagdollServiceServer,character : Model)
local humanoidRootPart = character.HumanoidRootPart
for _, part : Part in character:GetDescendants() do
if not part:IsA("BasePart") or part:FindFirstChildOfClass("Accessory") or part.Name == "Handle" or part.Name == "Torso" or part.Name == "HumanoidRootPart" then
continue
end
if not self.CFrameOffsets[part.Name] then
continue
end
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
local joint = Instance.new("BallSocketConstraint")
attachment0.Name = "RAGDOLL_ATTACHMENT"
attachment0.CFrame = self.CFrameOffsets[part.Name].CFrame[2]
attachment0.Parent = part
attachment1.Name = "RAGDOLL_ATTACHMENT"
attachment1.CFrame = self.CFrameOffsets[part.Name].CFrame[1]
attachment1.Parent = humanoidRootPart
joint.Name = "RAGDOLL_CONSTRAINT"
joint.Attachment0 = attachment0
joint.Attachment1 = attachment1
joint.Parent = part
part.Massless = true
end
end
function RagdollServiceServer.DestroyJoints(self : RagdollServiceServer,character : Model)
character.HumanoidRootPart.Massless = false
for _, instance : Instance in character:GetDescendants() do
if instance.Name == "RAGDOLL_ATTACHMENT" or instance.Name == "RAGDOLL_CONSTRAINT" then
instance:Destroy()
end
end
end
function RagdollServiceServer.EnableCollisions(self : RagdollServiceServer, character : Model, enabled : boolean)
for _, part : Part in character:GetChildren() do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
part.CanCollide = not enabled
part.Collide.CanCollide = enabled
end
end
end
function RagdollServiceServer.RequestRagdoll(self : RagdollServiceServer,player : Player, ragdoll : boolean)
local character = player.Character
if character == nil then
return
end
if ragdoll == true then
self:Ragdoll(character)
else
self:UnRagdoll(character)
end
end
function RagdollServiceServer.GetPlayerState(self : RagdollServiceServer,player : Player)
return self.RagdollStates[player.UserId]
end
function RagdollServiceServer.Ragdoll(self : RagdollServiceServer,character : Model)
local player = Players:GetPlayerFromCharacter(character)
if self:GetPlayerState(player) == true then
return
end
self.RagdollStates[player.UserId] = true
if player then
self.Networker:fire(player,"Ragdoll")
end
self:EnableMotor6D(character,false)
self:BuildJoints(character)
self:EnableCollisions(character,true)
end
function RagdollServiceServer.UnRagdoll(self : RagdollServiceServer,character : Model)
local player = Players:GetPlayerFromCharacter(character)
if self:GetPlayerState(player) == false then
return
end
self.RagdollStates[player.UserId] = false
self:DestroyJoints(character)
self:EnableMotor6D(character,true)
self:EnableCollisions(character,false)
self.Networker:fire(player,"UnRagdoll")
end
type RagdollServiceServer = typeof(RagdollServiceServer)
return RagdollServiceServer