Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

hey, can you help me in roblox coding?

  1. User

    hey, can you help me in roblox coding?

  2. Assistant

    Sure, I can help you in Roblox coding. What do you need help with?

  3. 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

  4. 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 ActivateRagdoll and DeactivateRagdoll, which trigger the activateRagdoll and deactivateRagdoll functions respectively on the player's character.

    When activateRagdoll is called, it sets every part that is a BasePart to be unanchored and applies a random velocity and gyroscopic force to simulate ragdoll physics. When deactivateRagdoll is called, it re-anchors all the parts and removes the BodyVelocity and BodyGyro instances that were added during activateRagdoll.

    The setupCharacter function 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 RemoteEvent in ReplicatedStorage with the names ActivateRagdoll and DeactivateRagdoll, and you can call them on the server using :FireServer(player, character) where player is the Player object and character is 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.

  5. User

    now, these lines of codes do i put them into a modulescript, localscript or serverscript?

  6. Assistant

    You should put this code in a Script or a LocalScript if you want it to run on the client, or in a ServerScriptService script 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 the activateRagdoll and deactivateRagdoll functions by using ragdollModule.activateRagdoll(character) or ragdollModule.deactivateRagdoll(character), where character is a reference to the player's character.

  7. User

    i got this error after putting it in a localscript: "Expected identifier when parsing variable name, got ",""

  8. 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.

  9. 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
    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)

  10. 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.

  11. 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
    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)

  12. 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 the function( and parent. This line should just be:

    part.AncestryChanged:Connect(function(parent)
    

    Once you remove the extra comma, this error should be resolved.

  13. User

    theres no part.ancestrychanged function..

  14. Assistant

    I apologize for the confusion. The correct function to use here would be part.AncestryChanged, not part.DescendantAdded.

    In the setupCharacter function, 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.

  15. 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
    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)

  16. Assistant

    Here is the updated version of the code with the changes to the setupCharacter function 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.

  17. User

    it stlll gives me the comma error at line 27 and line 53..

  18. Assistant

    I apologize, there seems to be a typo on the line where deactivateRagdoll function is defined. The loop is missing the variable name before part. 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
    end
    

    Regarding the error on line 27, it's caused by an extra comma in the parameter list of the anonymous function inside the AncestryChanged event. You can fix it by removing the , before parent. The updated line should look like this:

    	part.AncestryChanged:Connect(function(_,
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.