I want to make a block that when touching it makes a “ragdoll” to the player who touches it for a few seconds, I have tried some scripts, but so far I do not have a solution to this problem, please help!
Your question seems a little unclear. Are you asking for help creating the ragdoll or help scripting the ragdoll only firing after the player touches it for a few seconds?
I’m asking for help to make a block that makes ragdoll when you touch it, hope to be as clear as possible, sorry btw.
When it comes to making the ragdoll effect, I’m not entirely sure, but I think you could find out on the devforum and maybe look up some tutorials. Here is something I tried in a baseplate and it worked:
local debounce = false
script.Parent.Touched:Connect(function(hit)
local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart and debounce == false then
debounce = true
print(hit.Name)
local mag = (HumanoidRootPart.Position - script.Parent.Position).Magnitude
if mag <= 10 then --player is within 10 studs of the object, change to however close you want them to stay to the part. If you want them to touch the part the entire time, then it will require a little guess and check to get the number right.
print("initial contact reached")
wait(5)--change this to however many seconds you want the player to touch the part
local mag2 = (HumanoidRootPart.Position - script.Parent.Position).Magnitude
if mag2 <= 10 then
--code to input ragdoll effect
wait(3)
debounce = true
end
end
end
end)
--something that might mess it up a little bit if is the player ragdolls, and then flips onto the part. This can be fixed by adding another if then loop to check whether the player is ragdolled yet or not.
If the player touches the part, it waits a few seconds, then checks if the player is still touching the part or if they have moved away. If they haven’t, then input your ragdoll code.
Btw this is a server script inside a part.
Thanks dude, I will use this script and tell you if it works!
Realmente no se casi nada sobre script, hice esto, no funcionó, solo pegue el script de ragdoll en dónde debe ir dentro de este script
local debounce = false
script.Parent.Touched:Connect(function(hit)
local HumanoidRootPart = hit.Parent:FindFirstChild(“HumanoidRootPart”)
if HumanoidRootPart and debounce == false then
debounce = true
print(hit.Name)
local mag = (HumanoidRootPart.Position - script.Parent.Position).Magnitude
if mag <= 10 then
print(“initial contact reached”)
wait(5)–change this to however many seconds you want the player to touch the part
local mag2 = (HumanoidRootPart.Position - script.Parent.Position).Magnitude
if mag2 <= 10 then
local Debris = game:GetService("Debris")
local PhysicsService = game:GetService("PhysicsService")
local plr = script.Parent.Parent
local character = plr.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = flag_BreakJointsOnDeath
local constraints = script:WaitForChild("constraints")
repeat wait() until #constraints:GetChildren() >= 8
local variables = script:WaitForChild("variables")
local var_ragdoll = variables:WaitForChild("ragdoll")
local events = script:WaitForChild("events")
-- Folders -----------------------------------------------
local constraintfolder
pcall(function() constraintfolder = character.RagdollConstraints end)
if not constraintfolder then constraintfolder = Instance.new("Folder",character); constraintfolder.Name = "RagdollConstraints" end
local collisionfolder
pcall(function() collisionfolder = character.CollisionConstraints end)
if not collisionfolder then collisionfolder = Instance.new("Folder",character); collisionfolder.Name = "CollisionConstraints" end
-- Joint disabler ----------------------------------------
-- list of Motor6Ds that will be disabled while ragdoll is on
local motor6Dnames = {
"LeftAnkle";
"LeftWrist";
"LeftElbow";
"LeftKnee";
"LeftShoulder";
"LeftHip";
"RightAnkle";
"RightWrist";
"RightElbow";
"RightKnee";
"RightShoulder";
"RightHip";
--"Root";
"Waist";
"Neck";
}
-- scan for motors then add them to the table along with Part0, Part1 information
local motortbl = {}
function scanMotors()
for _,v in pairs(character:GetChildren()) do
if v:IsA("BasePart") then
for _,b in pairs(v:GetChildren()) do
local found = false
for _,c in pairs(motor6Dnames) do
if c == b.Name then
found = true
break
end
end
pcall(function() if found then table.insert(motortbl,{b,b.Part0,b.Part1}) end end)
end
end
end
end
-- create alternative 'Root' Motor6D to be used to attach RootPart while ragdoll is on
-- (if CanCollide=false RootPart remains attached to LowerTorso, it might end up in the
-- ground allowing player's camera to go through the ground. Solution? Use UpperTorso.)
local originalroot = character.LowerTorso.Root
local altroot = Instance.new("Motor6D",character.UpperTorso)
altroot.C0 = CFrame.new(0,(character.LowerTorso.Size.Y)*0.7,0)
altroot.Part0 = character.HumanoidRootPart
altroot.Part1 = nil
-- functions go through table made of all scanned motors and enable/disable them
function disableMotors()
for i=1,#motortbl do
pcall(function()
motortbl[i][1].Part1 = nil
end)
end
end
function restoreMotors()
for i=1,#motortbl do
pcall(function()
motortbl[i][1].Part1 = motortbl[i][3]
end)
end
end
-- Ragdoll builder ---------------------------------------
local constraints = constraints:GetChildren()
-- makes joints (fun fact: it finds the right constraint type in attachmentName)
function ragdollJoint(part0, part1, attachmentName)
local constraintname
for _,v in pairs(constraints) do
if string.match(attachmentName,v.Name) then
constraintname = v.Name
break
end
end
attachmentName = attachmentName.."RigAttachment"
local constraint = script.constraints[constraintname]:Clone()
constraint.Attachment0 = part0[attachmentName]
constraint.Attachment1 = part1[attachmentName]
constraint.Name = "RagdollConstraint"..part1.Name
constraint.Parent = constraintfolder
end
-- find the rig attachments, R6 doesn't have them so I prefer R15
function getAttachment0(attachmentName)
for _,child in next,character:GetChildren() do
local attachment = child:FindFirstChild(attachmentName)
if attachment then
return attachment
end
end
end
-- run ragdollJoint function for all bodyparts with the correct constraint type
function makejoints()
ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist")
ragdollJoint(character.UpperTorso, character.Head, "Neck")
ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist")
ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist")
ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee")
ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee")
ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle")
ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle")
ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder")
ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow")
ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder")
ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow")
ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip")
ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip")
end
-- welds are broken by explosions but constraints aren't so even accessories get them
function makeaccessoryjoints()
for _,child in next,character:GetChildren() do
pcall(function()
if child:IsA("Accessory") then
for _,part in next,child:GetChildren() do
if part:IsA("BasePart") then
part.CustomPhysicalProperties = PhysicalProperties.new(0,0,0,0,0)
local attachment1 = part:FindFirstChildOfClass("Attachment")
local attachment0 = getAttachment0(attachment1.Name)
if attachment0 and attachment1 then
local constraint = Instance.new("HingeConstraint")
constraint.Name = child.Name
constraint.Attachment0 = attachment0
constraint.Attachment1 = attachment1
constraint.LimitsEnabled = true
constraint.UpperAngle = 0
constraint.LowerAngle = 0
constraint.Parent = constraintfolder
end
end
end
end
end)
end
end
-- custom cylinder-shaped collision box
local cyl = Instance.new("Part",character.Head)
cyl.Name = "headcollisionbox"
cyl.Shape = Enum.PartType.Cylinder
cyl.Transparency = 1
cyl.Size = Vector3.new(character.Head.Size.Y,character.Head.Size.Z,character.Head.Size.Z)
local headweld = Instance.new("Weld",cyl)
headweld.Part0 = character.Head
headweld.Part1 = cyl
headweld.C0 = headweld.C0*CFrame.fromOrientation(0,0,math.rad(-90))
-- get the noclip collision group, create if it doesn't exist
local physgroupsuccess, physgroup = pcall(function() return PhysicsService:GetCollisionGroupId("noclip") end)
if not physgroupsuccess then
physgroup = PhysicsService:CreateCollisionGroup("noclip")
for _,v in pairs(PhysicsService:GetCollisionGroups()) do
PhysicsService:CollisionGroupSetCollidable("noclip",v["name"],false)
end
end
PhysicsService:SetPartCollisionGroup(character.Head,"noclip")
-- create attachment and constraint to attach custom collision box like accessories earlier
local cylattach = Instance.new("Attachment",cyl)
cylattach.Orientation = Vector3.new(0,0,-90)
local cylconst = Instance.new("HingeConstraint")
cylconst.Name = "headboxhinge"
cylconst.Attachment0 = character.Head.FaceCenterAttachment
cylconst.Attachment1 = cylattach
cylconst.LimitsEnabled = true
cylconst.UpperAngle = 0
cylconst.LowerAngle = 0
cylconst.Parent = constraintfolder
character.HumanoidRootPart.CustomPhysicalProperties = PhysicalProperties.new(0,0,0,100,0)
character.Head.CustomPhysicalProperties = PhysicalProperties.new(0,0,0,100,0)
character.Head.OriginalSize.Value = Vector3.new(1,1,1)
character.Head.Size = Vector3.new(character.Head.Size.Z,character.Head.Size.Y,character.Head.Size.Z)
-- list of blacklisted collisions, Part0 and Part1 won't collide with each other.
local collisionfiltertbl = {
{
character.Head.headcollisionbox; --Part0
character.LeftUpperArm; --Part1
character.LeftUpperLeg; --Part1
character.LowerTorso; --Part1
character.RightUpperArm; --Part1
character.RightUpperLeg; --Part1
character.UpperTorso; --Part1
};
{
character.LeftFoot;
character.LowerTorso;
character.UpperTorso;
};
{
character.LeftHand;
character.LowerTorso;
character.UpperTorso;
};
{
character.LeftLowerArm;
character.LowerTorso;
character.UpperTorso;
};
{
character.LeftLowerLeg;
character.LowerTorso;
character.UpperTorso;
};
{
character.LeftUpperArm;
character.LeftUpperLeg;
character.LowerTorso;
character.RightUpperArm;
character.RightUpperLeg;
character.UpperTorso;
};
{
character.LeftUpperLeg;
character.LowerTorso;
character.RightUpperLeg;
character.UpperTorso;
};
{
character.RightFoot;
character.LowerTorso;
character.UpperTorso;
};
{
character.RightHand;
character.LowerTorso;
character.UpperTorso;
};
{
character.RightLowerArm;
character.LowerTorso;
character.UpperTorso;
};
{
character.RightLowerLeg;
character.LowerTorso;
character.UpperTorso;
};
{
character.RightUpperArm;
character.LeftUpperLeg;
character.LowerTorso;
character.LeftUpperArm;
character.RightUpperLeg;
character.UpperTorso;
};
{
character.RightUpperLeg;
character.LowerTorso;
character.LeftUpperLeg;
character.UpperTorso;
};
}
-- using the list above, nocollisionconstraints are made
function makecollisionfilters()
local collisionfolder = character:WaitForChild("CollisionConstraints")
for i=1,#collisionfiltertbl do
for b=2,#collisionfiltertbl[i] do
local constraint = Instance.new("NoCollisionConstraint",collisionfolder)
constraint.Name = collisionfiltertbl[i][1].Name.."<->"..collisionfiltertbl[i][b].Name
constraint.Part0 = collisionfiltertbl[i][1]
constraint.Part1 = collisionfiltertbl[i][b]
end
end
end
-- run above functions
makejoints()
if flag_MakeAccessoryConstraints then makeaccessoryjoints() end
scanMotors()
makecollisionfilters()
-- Ragdoll runner ----------------------------------------
function ragdoll(mode)
if mode == "dead" or mode == "ragdoll" then
local rootpart; pcall(function() rootpart = character.HumanoidRootPart end); if not rootpart then --[[warn("Couldn't create ragdoll");]] return end
rootpart.CanCollide = false
if mode ~= "dead" then events.phys:FireClient(plr,"phys_true"); events.phys:FireClient(plr,"animations_false") end
disableMotors()
originalroot.Part1 = nil
altroot.C0 = CFrame.new(0,(character.LowerTorso.Size.Y)*0.7,0)
altroot.Part1 = character.UpperTorso
humanoid.AutoRotate = false
if mode == "dead" and flag_CloneCharacter then
humanoid.AutoRotate = false
plr.CharacterRemoving:Connect(function()
character.Archivable = true
local charclone = character:Clone()
charclone.Name = plr.Name.."'s Ragdoll"
charclone.Humanoid.Health = 1
charclone.Humanoid.Health = 0
charclone.Humanoid.AutomaticScalingEnabled = false
charclone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
for _,v in pairs(charclone:GetChildren()) do
if v:IsA("BaseScript") then
v:Remove()
elseif v:IsA("Tool") then
for _,b in pairs(v:GetChildren()) do
if b:IsA("BaseScript") then
b:Remove()
end
end
end
end
for _,v in pairs(character:GetChildren()) do
if not v:IsA("BaseScript") and not v:IsA("Humanoid") then
v:Remove()
end
end
charclone.Parent = workspace
if flag_AutoCleanup and flag_CleanupTime then
Debris:AddItem(charclone,flag_CleanupTime)
end
for _,v in pairs(charclone:GetChildren()) do
if v:IsA("BasePart") then v:SetNetworkOwnershipAuto() end
end
end)
end
elseif mode == "restore" then
if humanoid.Health <= 0 then return end
events.phys:FireClient(plr,"phys_false")
events.phys:FireClient(plr,"animations_true")
restoreMotors()
altroot.Part1 = nil
originalroot.Part1 = character.LowerTorso
humanoid.AutoRotate = true
end
end
-- Events ------------------------------------------------
humanoid.Died:Connect(function()
pcall(ragdoll,"dead")
end)
humanoid:WaitForChild("HeadScale").Changed:Connect(function()
pcall(function() cyl.Size = Vector3.new(character.Head.Size.Y,character.Head.Size.Z,character.Head.Size.Z) end)
end)
events.phys.OnServerEvent:Connect(function(sender,content,second)
if sender == plr then
if content == "ragdoll" then
var_ragdoll.Value = not var_ragdoll.Value
elseif content == "forceragdoll" then
var_ragdoll.Value = true
elseif content == "die" then
humanoid.Health = 0
elseif content == "dmg" then
humanoid:TakeDamage(second)
end
end
end)
var_ragdoll.Changed:Connect(function()
if humanoid.Health > 0 then
if var_ragdoll.Value then
pcall(ragdoll,"ragdoll")
else
pcall(ragdoll,"restore")
wait(10)
end
end
end)--code to input ragdoll effectR
local plr = game.Players.LocalPlayer
local character = plr.Character
local humanoid = plr.Character:WaitForChild("Humanoid")
local events = script.Parent:WaitForChild("events")
workspace.ChildAdded:Connect(function(ch) --ragdoll becomes alive on clients when it's cloned, this makes sure it remains dead
if string.match(ch.Name,"'s Ragdoll") then
local humm = ch:WaitForChild("Humanoid")
humm.Health = 1
humm.Health = 0
end
end)
-- main client ---------------------------------------------------------------
events:WaitForChild("phys").OnClientEvent:Connect(function(state,second,third)
if state == "phys_true" then
game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
elseif state == "phys_false" then
game.Players.LocalPlayer.Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
humanoid.AutoRotate = true
elseif state == "animations_false" then
pcall(function() character.Animate.Disabled = true end)
for _,v in pairs(humanoid:GetPlayingAnimationTracks()) do
if v.Name ~= "EmoteAnim" and v.Animation.AnimationId ~= "rbxassetid://3762076872" then --example animation stop whitelist to prevent animations from stopping
v:Stop(0)
end
end
elseif state == "animations_true" then
pcall(function() character.Animate.Disabled = false end)
end
end)
game:GetService("ContextActionService"):BindAction("RagdollMe", function(_,input)
if input == Enum.UserInputState.Begin then
events.phys:FireServer("ragdoll")
end
end)
wait(3)
debounce = true
end
end
end
Well first of all you will need a ragdoll script as this one :
Ragdoll_Module
Then create a script in your part (that script is an example so if the module is different, you may have to change it a bit) :
part = script.Parent
local ragdoll = require(game:GetService("ServerStorage").Modules.Ragdoll)
local db = {}
part.Touched:Connect(function(hit)
if table.find(db, hit.Parent) then return end
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
table.insert(db, hit.Parent)
ragdoll.Start(hit.Parent)
task.wait(5)
table.remove(db, table.find(db, hit.Parent))
ragdoll.Stop(hit.Parent)
end
end)
And if you want the block to throw your character back when you ragdoll it, you can create a knockback module in a few lines (its pretty simple)