I am currently making a roleplay game, and the people in it keep asking for me to add a “R to Ragdoll” feature, but i don’t know how to make it and i didn’t find anything that helped me in the Forums, can anyone help me?
You would start by cloning the character, and then manually making joints (in the script) that are able to be freely affected by physics.
After hours of trying to figure out the problem, I figured it out. First, make a folder in ReplicatedStorage named,“RemoteEvents” and put two RemoteEvents in it, one called “Ragdoll” and the other called"UnRagdoll". Next, put a localscript into StarterCharacterScripts and use this code:
--Variables-- local UIS = game:GetService("UserInputService") local RemoteEvents = game.ReplicatedStorage.RemoteEvents local CAS = game:GetService("ContextActionService") local FreezeAction = "freezeMovement" Ragdoll = false --R detection script UIS.InputBegan:Connect(function(KeyPressed) if KeyPressed.KeyCode == Enum.KeyCode.R then if not Ragdoll then CAS:BindAction( FreezeAction, function() return Enum.ContextActionResult.Sink end, false, unpack(Enum.PlayerActions:GetEnumItems()) ) RemoteEvents.Ragdoll:FireServer() print("Ragdolled") wait(0.5) Ragdoll = true else RemoteEvents.UnRagdoll:FireServer() CAS:UnbindAction(FreezeAction) print("Unragdolled") wait(0.5) Ragdoll = false end end end)
Now that you got your first script, make another script in ServerScriptService and put this script in it:
--Variables-- local RagdollEvent = game.ReplicatedStorage.RemoteEvents.Ragdoll local UnRagdollEvent = RagdollEvent.Parent.UnRagdoll --Ragdoll script-- RagdollEvent.OnServerEvent:Connect(function(Player) for i,v in pairs(Player.Character:GetDescendants()) do if v:IsA("Motor6D") and v.Parent.Name ~= "HumanoidRootPart" then local Socket = Instance.new("BallSocketConstraint") local a1 = Instance.new("Attachment") local a2 = Instance.new("Attachment") a1.Parent = v.Part0 a2.Parent = v.Part1 Socket.Parent = v.Parent Socket.Attachment0 = a1 Socket.Attachment1 = a2 a1.CFrame = v.C0 a2.CFrame = v.C1 Socket.LimitsEnabled = true Socket.TwistLimitsEnabled = true v:Destroy() end end Player.Character.Humanoid.RequiresNeck = false Player.Character.Humanoid.Sit = true end) --Unragdoll script-- UnRagdollEvent.OnServerEvent:Connect(function(Player) for i,v in pairs(Player.Character:GetDescendants()) do if v:IsA("BallSocketConstraint") then v.UpperAngle = 0 v.TwistUpperAngle = 0 v.TwistLowerAngle = 0 local Joints = Instance.new("Motor6D",v.Parent) Joints.Part0 = v.Attachment0.Parent Joints.Part1 = v.Attachment1.Parent Joints.C0 = v.Attachment0.CFrame Joints.C1 = v.Attachment1.CFrame v:Destroy() end end Player.Character.Humanoid.Sit = false end)
Now it should work. I made these scripts just for this problem. It works better if you use r6 instead of r15. If you use r15, you might be able to perfect it with some tweaking. Happy holidays! I hope this helped!
This is exploitable, it shouldn’t be from remote events, it should be by a module script
Anything accessible to the client is theoretically exploitable (including module scripts). Additionally, I don’t see why anyone would want to unnaturally fire the remote event used, if that is what you’re talking about by saying “exploitable”.