I want to have my characters ragdoll on death with EchoReaper’s ragdoll script, but however seconds after the character is cloned the ragdoll starts to shake.
https://gyazo.com/e4f81e0e7463cf755e4e9070dff17bd6
I have tried anchoring the ragdoll, but that just makes it so the ragdoll is in its “t-pose” (a character with no animation)
CODE
RagdollTestScript
lua
--[[
This is a test file to demonstrate how ragdolls work. If you don't use
this file, you need to manually apply the Ragdoll tag to humanoids that
you want to ragdoll
--]]
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPack = game:GetService("StarterPack")
local StarterPlayer = game:GetService("StarterPlayer")
script.KillScript.Parent = StarterPlayer.StarterCharacterScripts
script.RagdollMe.Parent = StarterPlayer.StarterCharacterScripts
-- Enable this if you want to test ragdolls in zero - g
local ANTIGRAV_ENABLED = false
if ANTIGRAV_ENABLED then
script.Gravity.Parent = StarterPlayer.StarterCharacterScripts
workspace.Gravity = 0
end
local buildRagdoll = require(ReplicatedStorage:WaitForChild("buildRagdoll"))
-- Trying to clone something with Archivable=false will return nil for some reason
-- Helper function to enable Archivable, clone, reset Archivable to what it was before
-- and then return the clone
function safeClone(instance)
local oldArchivable = instance.Archivable
instance.Archivable = true
local clone = instance:Clone()
instance.Archivable = oldArchivable
return clone
end
function characterAdded(player, character)
player.Character:WaitForChild('Humanoid', 60)
player.Character:WaitForChild('HumanoidRootPart', 60)
wait(0.1)
local humanoid = character:FindFirstChildOfClass("Humanoid")
buildRagdoll(humanoid)
end
function characterRemoving(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
return
end
local clone = safeClone(character)
local cloneHumanoid = clone:FindFirstChildOfClass("Humanoid")
-- Don't clutter the game with nameplates / healthbars
cloneHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
-- Roblox will try to rebuild joints when the clone is parented to Workspace and
-- break the ragdoll, so disable automatic scaling to prevent that. We don't need
-- it anyway since the character is already scaled from when it was originally created
cloneHumanoid.AutomaticScalingEnabled = false
-- Clean up junk so we have less scripts running and don't have ragdolls
-- spamming random sounds
local animate = character:FindFirstChild("Animate")
local sound = character:FindFirstChild("Sound")
local health = character:FindFirstChild("Health")
if animate then
animate:Destroy()
end
if sound then
sound:Destroy()
end
if health then
health:Destroy()
end
clone.Parent = workspace
clone.Name = "Ragdoll"
-- State is not preserved when cloning. We need to set it back to Dead or the
-- character won't ragdoll. This has to be done AFTER parenting the character
-- to Workspace or the state change won't replicate to clients that can then
-- start simulating the character if they get close enough
cloneHumanoid:ChangeState(Enum.HumanoidStateType.Dead)
end
function playerAdded(player)
player.CharacterAdded:connect(function(character)
characterAdded(player, character)
end)
player.CharacterRemoving:Connect(characterRemoving)
if player.Character then
characterAdded(player, player.Character)
end
end
Players.PlayerAdded:connect(playerAdded)
-- Ugly hack because sometimes PlayerAdded doesn't fire in play solo
for _,player in pairs(Players:GetPlayers()) do
playerAdded(player)
end
StayStill (StarterCharacterScripts)
lua
local hum = script.Parent:WaitForChild("Humanoid")
local waist = script.Parent:WaitForChild("LowerTorso")
local died
died = script.Parent.Humanoid.Died:Connect(function()
hum.AutoRotate = false
hum.PlatformStand = true
--for _, object in pairs(script.Parent:GetChildren()) do
--object.Anchored = true
end)
LookScript
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Waist", true)
local YOffset = Neck.C0.Y
local CFNew, CFAng = CFrame.new, CFrame.Angles
local asin = math.asin
game:GetService("RunService").RenderStepped:Connect(function()
local CameraDirection = Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
if Neck then
if Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
Neck.C0 = CFNew(0, YOffset, 0) * CFAng(0, -asin(CameraDirection.x), 0) * CFAng(asin(CameraDirection.y), 0, 0)
elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
end
end
end)
game.ReplicatedStorage.look.OnClientEvent:Connect(function(otherPlayer, neckCFrame)
local Neck = otherPlayer.Character:FindFirstChild("Waist", true)
if Neck then
Neck.C0 = neckCFrame
end
end)
while wait(.001) do
game.ReplicatedStorage.look:FireServer(Neck.C0)
end
The script that is triggered when “look” is triggered
game.ReplicatedStorage.look.OnServerEvent:Connect(function(player, neckCFrame)
for key, value in pairs(game.Players:GetChildren()) do
if value ~= player then
game.ReplicatedStorage.look:FireClient(value, player, neckCFrame)
end
end
end)
Other details:
I use a startercharacter and edited the code to make it work with startercharacters.
I have a script that makes the character’s waist follow the camera.
I have a script that follows the head rather than the humanoidrootpart.