hey, can you help me with roblox coding?
- User
hey, can you help me with roblox coding?
- Assistant
Sure! What do you need help with?
- User
alright so, i got planned to do an r6 ragdoll system that is triggered with remote events and that can be triggered with fireserver on another scripts, so i've got two remote events on replicatedstorage: one being named "ActivateRagdoll" and another one named "Deactivate Ragdoll" the system i am making has cool features such as: bouncing bodyparts after falling and touching the floor, aswell gravitational effects (for example head's more heavier than the rest of the body), right now i got the localscript that has the ragdoll system on serverscriptservice , heres the code:
local Players = game:GetService("Players")
local function activateRagdoll(character) for _, part in ipairs(character:GetDescendants()) do if part:IsA("BasePart") then part.Anchored = false local rb = part:FindFirstChildOfClass("BodyVelocity") or Instance.new("BodyVelocity") rb.Velocity = Vector3.new( math.random(-50, 50), math.random(50, 100), math.random(-50, 50) ) rb.MaxForce = Vector3.new(math.huge, math.huge, math.huge) rb.Name = "RagdollVelocity" rb.Parent = part
local bg = part:FindFirstChildOfClass("BodyGyro") or Instance.new("BodyGyro") bg.D = 1000 bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge) bg.Name = "RagdollGyro" bg.Parent = part -- Add TouchEnded event to apply upward force when colliding with floor if part.Name ~= "HumanoidRootPart" then part.Touched:Connect(function(hit) if hit and hit:IsA("BasePart") and hit.Position.Y < part.Position.Y then local rb = part.RagdollVelocity if rb then local upForce = Vector3.new(0, math.random(100, 300), 0) rb:AddForce(upForce) end end end) end -- Adjust mass for gravitational effects if part.Name == "Head" then part.Mass = 2 else part.Mass = 1 end end endend
local function deactivateRagdoll(character) for _, part in ipairs(character:GetDescendants()) do if part:IsA("BasePart") then part.Anchored = true local rv = part:FindFirstChild("RagdollVelocity") if rv then rv:Destroy() end local rg = part:FindFirstChild("RagdollGyro") if rg then rg:Destroy() end end end end
local function onActivateRagdoll(player, character) activateRagdoll(character) end
local function onDeactivateRagdoll(player, character) deactivateRagdoll(character) end
local function setupCharacter(character) character.DescendantAdded:Connect(function(part) if part:IsA("BasePart") then -- Add TouchEnded event to new parts if part.Name ~= "HumanoidRootPart" then part.Touched:Connect(function(hit) if hit and hit:IsA("BasePart") and hit.Position.Y < part.Position.Y then local rb = part.RagdollVelocity if rb then local upForce = Vector3.new(0, math.random(100, 300), 0) rb:AddForce(upForce) end end end) end
-- Adjust mass for new parts if part.Name == "Head" then part.Mass = 2 else part.Mass = 1 end end end) -- Add initial mass adjustments for _, part in ipairs(character:GetDescendants()) do if part:IsA("BasePart") then if part.Name == "Head" then part.Mass = 2 else part.Mass = 1 end end endend
Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) setupCharacter(character) end) end)
for _, player in ipairs(Players:GetPlayers()) do if player.Character then setupCharacter(player.Character) end end
game.ReplicatedStorage.ActivateRagdoll.OnServerEvent:Connect(onActivateRagdoll) game.ReplicatedStorage.DeactivateRagdoll.OnServerEvent:Connect(onDeactivateRagdoll)
now, i am gonna show you the code that has the ragdoll triggering lines (ActivateRagdoll:FireServer(character), DeactivateRagdoll:FireServer(character)):
local TM = require(script.Parent.Parent:WaitForChild("ToolManagment")) local Tween = require(script.Parent.Parent:WaitForChild("Module_Management"):WaitForChild("Tweening")) local GetUp2 = require(script.Parent.Parent:WaitForChild("GetUp")) local ReplicatedStorage = game:GetService("ReplicatedStorage") local ActivateRagdoll = ReplicatedStorage:WaitForChild("ActivateRagdoll") local DeactivateRagdoll = ReplicatedStorage:WaitForChild("DeactivateRagdoll") local character = game.Players.LocalPlayer.Character --GetUp2:GetUp()
local Direction = Enum.EasingDirection.In local Style = Enum.EasingStyle.Sine local Duration = 0.13 local CFRAME_HERE_RL = CFrame.new(0.8,-1.5,0.8) * CFrame.fromEulerAnglesXYZ(-math.pi/4,-0.5,0.3) local CFRAME_HERE_LA = CFrame.new(-1.75,0.25,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,4,-4) local CFRAME_HERE_RA = CFrame.new(1.75,0.25,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,4) local CFRAME_HERE_LL = CFrame.new(1.75,0.25,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,4) local CFRAME_HERE_LL = CFrame.new(-1.5,0.5,0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,-4) local CFRAME_HERE_RA2 = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,4) --BUTTON UP ANIMS local RL = CFrame.new(0.7,-1,-1.5) * CFrame.fromEulerAnglesXYZ(math.pi/2.3,0,0) local LA = CFrame.new(-1.75,0.25,0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,-4) local LL = CFrame.new(-0.5,-1.5,-1) * CFrame.fromEulerAnglesXYZ(math.pi/9,0,0) local RA = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,4) local LA1 = CFrame.new(-1.75,0.25,0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,-4) local RL2 = CFrame.new(0.7,-1,-1.5) * CFrame.fromEulerAnglesXYZ(math.pi/2.3,0,0.3)
local LEFTARM = CFrame.new(-1.75,0.25,0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,-4) local RIGHTARM = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(-math.pi/1,-4,4) local LEFTLEG = CFrame.new(-0.7,-1,-1.5) * CFrame.fromEulerAnglesXYZ(math.pi/2.3,0,0)
Kick = false Equipped = false Tool = script.Parent Player = game.Players.LocalPlayer Mouse = Player:GetMouse()
script.Parent.Equipped:connect(function(m) Equipped = true end)
script.Parent.Unequipped:connect(function(m) Equipped = false end)
Mouse.KeyDown:connect(function(key) if Equipped == false then return end if TM.GetUsing() then return end if key ~= "x" then return end TM.SetUsing(true) Player.Character.Torso.RotVelocity = Vector3.new() Player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
local BV = Instance.new("BodyVelocity", Player.Character.HumanoidRootPart) BV.Velocity = Vector3.new(0, -5, 0) BV.MaxForce = Vector3.new(0, 2000, 0) game.Debris:AddItem(BV, 1) if TM.check() == "R" then TM.EditWeld("Right Leg", CFrame.new(0.5,-1.5,0.8) * CFrame.fromEulerAnglesXYZ(-math.pi/2.5,0,0)) Tween.TweenWeld("Left Arm", CFrame.new(-1.5,0,0), CFRAME_HERE_LA, Direction, Style, Duration) Tween.TweenWeld("Right Arm", CFrame.new(1.5,0,0), CFRAME_HERE_RA, Direction, Style, Duration) Tween.TweenWeld("Left Leg", CFrame.new(-0.5,-2,0), LEFTLEG, Direction, Style, Duration) Player.Character["HumanoidRootPart"].CFrame = Player.Character["HumanoidRootPart"].CFrame + Vector3.new(0, 2.2, 0) Player.Character["HumanoidRootPart"].CFrame = Player.Character["HumanoidRootPart"].CFrame * CFrame.fromEulerAnglesXYZ(1.5,0,0) Player.Character.Humanoid.PlatformStand = true wait(0.13) TM.EditWeld("Left Leg", CFrame.new(-0.5,-1.5,0.8) * CFrame.fromEulerAnglesXYZ(-math.pi/2.5,0,0)) Tween.TweenWeld("Right Leg", CFrame.new(0.5,-2,0), RL, Direction, Style, 0) Tween.TweenWeld("Left Arm", CFrame.new(-1.5,0,0), LA, Direction, Style, 0) Tween.TweenWeld("Right Arm", CFrame.new(1.5,0,0), RA, Direction, Style, 0) else Tween.TweenWeld("Right Leg", CFrame.new(0.5,-2,0), RL, Direction, Style, Duration) TM.EditWeld("Left Leg", CFrame.new(-0.5,-1.5,0.8) * CFrame.fromEulerAnglesXYZ(-math.pi/2.5,0,0)) Tween.TweenWeld("Right Arm", CFrame.new(1.5,0,0), CFRAME_HERE_RA, Direction, Style, Duration) Tween.TweenWeld("Left Arm", CFrame.new(-1.5,0,0), CFRAME_HERE_LA, Direction, Style, Duration) Player.Character["HumanoidRootPart"].CFrame = Player.Character["HumanoidRootPart"].CFrame + Vector3.new(0, 2.2, 0) Player.Character["HumanoidRootPart"].CFrame = Player.Character["HumanoidRootPart"].CFrame * CFrame.fromEulerAnglesXYZ(1.5,0,0) Player.Character.Humanoid.PlatformStand = true wait(0.13) TM.EditWeld("Right Leg", CFrame.new(0.5,-1.5,0.8) * CFrame.fromEulerAnglesXYZ(-math.pi/2.5,0,0)) Tween.TweenWeld("Left Leg", CFrame.new(-0.5,-2,0), LEFTLEG, Direction, Style, 0) Tween.TweenWeld("Right Arm", CFrame.new(1.5,0,0), RA, Direction, Style, 0) Tween.TweenWeld("Left Arm", CFrame.new(-1.5,0,0), LA, Direction, Style, 0) end Player.Character["Torso"].CollisionGroupId = 2 Player.Character["Head"].CollisionGroupId = 2 Kick = true wait(0.4) Player.Character.Humanoid.AutoRotate = false --here goes the ragdoll code ActivateRagdoll:FireServer(character) --this is where i want the ragdoll to trigger wait(10) --here you disable the ragdoll code DeactivateRagdoll:FireServer(character) GetUp2:GetUp() wait(1) TM.SetUsing(false)end)
Player.Character["Right Leg"].Touched:connect(function(hit) if TM.check() == "L" then return end if hit.Name ~= "TPS" then return end if Kick == false then return end local force = Player.Character["Right Leg"].CFrame.lookVector * 80 local angle = Vector3.new(2e+003,2e+003,2e+003) Kick = false TM.ApplyForce(hit, angle, force, "Right Leg") end)
Player.Character["Left Leg"].Touched:connect(function(hit) if TM.check() == "R" then return end if hit.Name ~= "TPS" then return end if Kick == false then return end local force = Player.Character["Left Leg"].CFrame.lookVector * 80 local angle = Vector3.new(2e+003,2e+003,2e+003) Kick = false TM.ApplyForce(hit, angle, force, "Left Leg") end)
function ChangeOwner(ball) game.ReplicatedStorage.ChangeOwner:FireServer(ball) end
its a code made with cframes and its meant to be like that, if you see any issues with the ragdoll you can tell me. i have also tried it many times but my avatar just freezes and stays in the last cframe line, only way to fix it is respawning my avatar but i just want the ragdoll to trigger where'd i want.
- Assistant
It looks like you are on the right track with the ragdoll system. However, without a clear idea of what the issue is, it's hard to tell what the problem might be.
That being said, a few things that you could check for:
-
Make sure that the remote events are being called correctly. You can use print statements to debug this, to see whether the functions
onActivateRagdollandonDeactivateRagdollare being called when the remote events are triggered. -
Check whether the
charactervariable is being passed into the functionsonActivateRagdollandonDeactivateRagdoll. You can use print statements to debug this as well, to make sure that thecharactervariable is not nil. -
Make sure that the
setupCharacterfunction is being called for the LocalPlayer's character. You can check this using print statements as well. -
Finally, try commenting out parts of the code to isolate any issues. For example, you can disable the CFrame animations and see whether the ragdoll system works correctly. This way, you can pinpoint where the issue might be.
I hope this helps! Let me know if you have any other questions.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.