hey, can you help me in roblox coding?
- User
hey, can you help me in roblox coding?
- Assistant
Sure, I can help you in Roblox coding. What do you need help with?
- User
so, i got planned into making a r6 ragdoll system that triggers with a remote event, that can be triggered into another script and that also has good features such as: bouncing body parts when hitting the ground, gravitational effects (for example, head's can be more heavy than body), that can also be triggered on a localplayer and can be seen on server sided(other players screens) and viceversa
- Assistant
Sure, I can help you with that. Here's an example script to help you get started:
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 end end end 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 part.AncestryChanged:Connect(function(_, parent) if not parent:IsDescendantOf(character) then deactivateRagdoll(character) end end) end end) end 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)This script listens for remote events
ActivateRagdollandDeactivateRagdoll, which trigger theactivateRagdollanddeactivateRagdollfunctions respectively on the player's character.When
activateRagdollis called, it sets every part that is aBasePartto be unanchored and applies a random velocity and gyroscopic force to simulate ragdoll physics. WhendeactivateRagdollis called, it re-anchors all the parts and removes theBodyVelocityandBodyGyroinstances that were added duringactivateRagdoll.The
setupCharacterfunction sets up listeners to automatically deactivate ragdoll if the player's character gets cloned or destroyed.To use this script, you just need to make sure you have a
RemoteEventinReplicatedStoragewith the namesActivateRagdollandDeactivateRagdoll, and you can call them on the server using:FireServer(player, character)whereplayeris thePlayerobject andcharacteris their character. You can also trigger the events from client-side scripts using:FireServer()and listening to the events on the server as shown in the script above. - User
now, these lines of codes do i put them into a modulescript, localscript or serverscript?
- Assistant
You should put this code in a
Scriptor aLocalScriptif you want it to run on the client, or in aServerScriptServicescript if you want it to run on the server.If you want to create a module out of this code, you could create a new ModuleScript in the Explorer window, copy and paste the code into it, and save it under a unique name. You can then require this module in other scripts on the client or server.
To require it, you can use
local ragdollModule = require(script.Parent.RagdollModule), if the module is in the same folder as the script you want to require it in. You would then call theactivateRagdollanddeactivateRagdollfunctions by usingragdollModule.activateRagdoll(character)orragdollModule.deactivateRagdoll(character), wherecharacteris a reference to the player's character. - User
i got this error after putting it in a localscript: "Expected identifier when parsing variable name, got ",""
- Assistant
This error is usually caused by a syntax error, usually an error in the way you've written the code.
Make sure you have copied the entire code correctly, including all of the commas and parentheses. It's possible that there is a missing or extra comma somewhere that is causing the error.
Also, make sure the code doesn't have any extra or missing brackets.
If you're still unable to resolve the issue, please provide me with your code and I can help you further.
- User
heres the entire 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 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 part.AncestryChanged:Connect(function(, parent) if not parent:IsDescendantOf(character) then deactivateRagdoll(character) end end) end end) end
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)
- Assistant
The error in your code is on this line:
bg.Name ="“RagdollGyro"In this line, there is an extra character
", after the=sign. It should be removed so that the line reads:bg.Name = "RagdollGyro"Once you make this change, the code should work correctly in a LocalScript.
- User
it still gives me the same comma error, heres the code again:
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 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 part.AncestryChanged:Connect(function(, parent) if not parent:IsDescendantOf(character) then deactivateRagdoll(character) end end) end end) end
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)
- Assistant
I apologize for missing the error earlier. The error on line 26 is due to an extra comma inside the function:
part.AncestryChanged:Connect(function(, parent)There is an extra
,in between thefunction(andparent. This line should just be:part.AncestryChanged:Connect(function(parent)Once you remove the extra comma, this error should be resolved.
- User
theres no part.ancestrychanged function..
- Assistant
I apologize for the confusion. The correct function to use here would be
part.AncestryChanged, notpart.DescendantAdded.In the
setupCharacterfunction, change this line:character.DescendantAdded:Connect(function(part)to this:
character.AncestryChanged:Connect(function(_, parent)And change this line:
part.AncestryChanged:Connect(function(, parent)to this:
part.AncestryChanged:Connect(function(_, parent)Once these changes have been made, the code should run without any syntax errors.
- User
can you please update it..? 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 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 part.AncestryChanged:Connect(function(, parent) if not parent:IsDescendantOf(character) then deactivateRagdoll(character) end end) end end) end
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)
- Assistant
Here is the updated version of the code with the changes to the
setupCharacterfunction I mentioned: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 end end end 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 part.AncestryChanged:Connect(function(_, parent) if not parent:IsDescendantOf(character) then deactivateRagdoll(character) end end) end end) end 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)This updated code should work as expected with no syntax errors.
- User
it stlll gives me the comma error at line 27 and line 53..
- Assistant
I apologize, there seems to be a typo on the line where
deactivateRagdollfunction is defined. The loop is missing the variable name beforepart. It should read as follows: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 endRegarding the error on line 27, it's caused by an extra comma in the parameter list of the anonymous function inside the
AncestryChangedevent. You can fix it by removing the,beforeparent. The updated line should look like this:part.AncestryChanged:Connect(function(_,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.