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

hey, can you help me with roblox coding real quick?

  1. User

    hey, can you help me with roblox coding real quick?

  2. Assistant

    Sure, what do you need help with in Roblox coding?

  3. User

    alright so, i am trying to make a realistic r6 ragdoll that can trigger with an remote event

  4. Assistant

    Okay, to create a realistic R6 ragdoll that can be triggered with a RemoteEvent, follow these steps:

    1. Create a new ServerScriptService script and name it "RagdollScript".

    2. In the RagdollScript, create a new RemoteEvent instance.

    local ragdollEvent = Instance.new("RemoteEvent")
    
    ragdollEvent.Name = "RagdollEvent"
    
    ragdollEvent.Parent = game:GetService("ReplicatedStorage")
    
    1. Next, create a new function called "ragdollPlayer" that will be called when the RemoteEvent is fired. This function will first check if the player is already ragdolled, and if not, it will set the player's humanoid root part to "Anchored" and kill the player's humanoid object to trigger the ragdoll effect.

      local function ragdollPlayer(player)
          local character = player.Character or player.CharacterAdded:Wait()
          local humanoid = character:FindFirstChildOfClass("Humanoid")
        
          if humanoid.RigType == Enum.HumanoidRigType.R6 and not character:FindFirstChild("Ragdoll") then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(1)
            torso.Anchored = false
            
            local humanoid = Instance.new("Humanoid")
            humanoid.Parent = character
            humanoid.Name = "Humanoid"
          end
      end
      
    2. Now, you need to connect the RemoteEvent to the "ragdollPlayer" function so that it is called when the event is fired.

    ragdollEvent.OnServerEvent:Connect(function(player)
        ragdollPlayer(player)
    end)
    
    1. Finally, in the LocalScript where you want to trigger the ragdoll, call the RemoteEvent "FireServer" method with the local player as an argument.

      local ragdollEvent = game:GetService("ReplicatedStorage").RagdollEvent
      
      ragdollEvent:FireServer(game.LocalPlayer)
      

    Now, when a player fires the RemoteEvent, their character will ragdoll and their humanoid will be replaced with a ragdoll model.

  5. User

    the serverscriptservice its a regular script right? or is it a modulescript?

  6. Assistant

    Yes, the ServerScriptService is a service in Roblox that has many different types of objects that you can create within it, including regular Scripts and ModuleScripts. In this case, you can create a regular Script within the ServerScriptService to hold the code for your RemoteEvent and ragdoll function.

  7. User

    hey so uhh. the script didnt work at all..

  8. Assistant

    I'm sorry to hear that. Can you please tell me what errors or issues you're encountering when running the script? That way, I can better understand what might be going wrong and help troubleshoot the problem.

  9. User

    well, i put the ragdoll code in the localscript so its triggered, but nothing happens, the right, left, torso and right leg stays still and it doesnt move

  10. Assistant

    Ah, it sounds like the code may not be running correctly on the server-side. I would recommend moving the entire ragdoll code into the ServerScriptService script instead of the LocalScript. This way, the RemoteEvent handling and the ragdolling of the player will happen entirely on the server-side rather than relying on the LocalScript to function correctly.

    Here's what the updated ServerScriptService code would look like:

    local ragdollEvent = Instance.new("RemoteEvent")
    ragdollEvent.Name = "RagdollEvent"
    ragdollEvent.Parent = game:GetService("ReplicatedStorage")
    
    local function ragdollPlayer(player)
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        
        if humanoid.RigType == Enum.HumanoidRigType.R6 and not character:FindFirstChild("Ragdoll") then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(1)
            torso.Anchored = false
            
            local humanoid = Instance.new("Humanoid")
            humanoid.Parent = character
            humanoid.Name = "Humanoid"
        end
    end
    
    ragdollEvent.OnServerEvent:Connect(function(player)
        ragdollPlayer(player)
    end)
    

    Then, in your LocalScript, you can call the RemoteEvent to trigger the ragdoll like this:

    local ragdollEvent = game:GetService("ReplicatedStorage").RagdollEvent
    
    ragdollEvent:FireServer()
    

    Make sure to remove any ragdoll-related code from the LocalScript once you've moved it into the ServerScriptService. This should ensure that the ragdolling works correctly and consistently for all players who trigger the RemoteEvent.

  11. User

    sooo, it kinda worked, but my character just fell without executing any ragdoll, the hats went off and i couldnt reset to fix the problem, it also gave me this error: "ServerScriptService.RagdollScript:14: attempt to index nil with 'Clone'"

  12. Assistant

    I'm sorry to hear that the issue is not completely resolved yet. That error typically occurs when the "Ragdoll" object is not found within the "Humanoid" object. It's possible that it's named differently in your version of the game, so you'll want to make sure that the ragdoll object is named correctly within the humanoid object.

    As for the character just falling without executing any ragdoll, it could be because the ragdoll effect is not lasting long enough. You can try increasing the wait time before unanchoring the torso:

    torso.Anchored = true
    wait(2) -- Increase the wait time to 2 seconds
    torso.Anchored = false
    

    Additionally, you can try adding a more comprehensive error-handling system that will print out errors whenever something goes wrong. Here's an updated version of the ragdoll function with an error message that should help with debugging:

    local function ragdollPlayer(player)
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        
        if humanoid.RigType == Enum.HumanoidRigType.R6 then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            if not ragdoll then
                print("Ragdoll object not found in humanoid.")
                return
            elseif character:FindFirstChild("Ragdoll") then
                print("Character is already ragdolled.")
                return
            end
            
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(2)
            torso.Anchored = false
            
            local humanoid = Instance.new("Humanoid")
            humanoid.Parent = character
            humanoid.Name = "Humanoid"
        else
            print("Character is not an R6 model.")
        end
    end
    

    This updated function will print out error messages to the console if it encounters any issues, such as not finding the ragdoll object or trying to ragdoll a character that is already ragdolled.

  13. User

    soo, it gave me "ragdoll object not found in humanoid", how do i fix it?

  14. Assistant

    If you're encountering the "Ragdoll object not found in humanoid" error, it could mean that the ragdoll object is not named correctly, or it's not present in the humanoid object.

    To fix the issue, first, make sure that the ragdoll object is present within the humanoid object. You can do this by opening the character model and checking if it has a child object named "Ragdoll". If it doesn't, you'll need to add it manually.

    To add the ragdoll object, you can create a new Model object and name it "Ragdoll", then add it as a child of the humanoid object. Next, you'll need to create the ragdoll by clicking on the "Enable" button in the "Ragdoll" object's Properties tab. Save the character model and try running the script again.

    If the ragdoll object is already present, double-check that it's named correctly exactly. It should spelled "Ragdoll" with a capital "R".

  15. User

    how do i add it as a child of the humanoid object?

  16. Assistant

    To add the "Ragdoll" object as a child of the "Humanoid" object, you can use the "Parent" property of the "Part" or "Instance" that you want to add as a child.

    Here is some example code that demonstrates how to add the "Ragdoll" Model object as a child of the "Humanoid" object:

    -- Get the character model and humanoid
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    
    -- Create the Ragdoll object
    local ragdoll = Instance.new("Model")
    ragdoll.Name = "Ragdoll"
    
    -- Add the Ragdoll object as a child of the Humanoid object
    ragdoll.Parent = humanoid
    

    With this code, the "Ragdoll" object will be created and then added as a child of the "Humanoid" object. Note that this code assumes that you have already defined the "player" variable, which should reference the player that you want to ragdoll.

    Once you have added the "Ragdoll" object to the character model, you should be able to run the ragdoll code without encountering the "Ragdoll object not found in humanoid" error.

  17. User

    it kinda worked, but when the player ragdolled, my camera and character froze for 2 seconds mid air, how do i fix it?

  18. Assistant

    The freezing issue could be due to the fact that the "Humanoid" object is being destroyed and then re-added to the character model during the ragdoll effect. This causes a brief period of time where the character has no humanoid, which can cause the camera and movement to freeze.

    To fix this issue, you can create a new humanoid object before destroying the old one, and then transfer any necessary properties (like player health) to the new humanoid object after it's been created. Here's what that updated ragdoll function would look like:

    local function ragdollPlayer(player)
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:FindFirstChildOfClass("Humanoid")
    
        if humanoid.RigType == Enum.HumanoidRigType.R6 then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            if not ragdoll then
                print("Ragdoll object not found in humanoid.")
                return
            elseif character:FindFirstChild("Ragdoll") then
                print("Character is already ragdolled.")
                return
            end
    
            -- Create a new humanoid object
            local newHumanoid = Instance.new("Humanoid")
            newHumanoid.Name = "Humanoid"
            newHumanoid.Health = humanoid.Health
            newHumanoid.MaxHealth = humanoid.MaxHealth
            newHumanoid.WalkSpeed = humanoid.WalkSpeed
            newHumanoid.JumpPower = humanoid.JumpPower
            newHumanoid.MoveDirection = humanoid.MoveDirection
            newHumanoid.MoveTo = humanoid.MoveTo
            newHumanoid.AutoRotate = humanoid.AutoRotate
            newHumanoid.Team = humanoid.Team
            newHumanoid.PlatformStand = humanoid.PlatformStand
            newHumanoid.RootPart = humanoid.RootPart
            
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(2)
            torso.Anchored = false
    
            newHumanoid.Parent = character
        else
            print("Character is not an R6 model.")
        end
    end
    

    With this updated code, the ragdolling process will still work as before, but instead of destroying the "Humanoid" object directly, it will create a new "Humanoid" object, transfer the necessary properties to it, and then destroy the old "Humanoid" object. This way, the player's character should not freeze in mid-air when ragdolling.

  19. User

    is the torso.anchored important? or can i remove it?

  20. Assistant

    The torso.Anchored = true line of the code is there to prevent the character from sliding or bouncing around while the ragdoll effect is taking place. By default, when a character's humanoid is destroyed, it reverts to the physics engine, which can cause the character to "fly" or "bounce" around after being ragdolled.

    By setting the "Anchored" property to true on the "Torso" or "UpperTorso" part of the character, it essentially pins the character to the position they were in when the ragdoll effect occurs, which makes the ragdoll more realistic and less jarring.

    It's generally not recommended to remove this line unless you want to change the behavior of the ragdoll effect. In most cases, leaving it in place will give you the best results.

  21. User

    it gives me this error "Unable to assign property MoveDirection. Property is read only"

  22. Assistant

    I apologize for the confusion - you're correct that the MoveDirection property cannot be set manually and is read-only.

    If you need to transfer the player's movement direction to the new humanoid object, you can use the Velocity property instead. This property controls the velocity vector of the humanoid's root part, which is what determines the player's movement direction and speed.

    Here's what that updated code would look like:

    local function ragdollPlayer(player)
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:FindFirstChildOfClass("Humanoid")
    
        if humanoid.RigType == Enum.HumanoidRigType.R6 then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            if not ragdoll then
                print("Ragdoll object not found in humanoid.")
                return
            elseif character:FindFirstChild("Ragdoll") then
                print("Character is already ragdolled.")
                return
            end
    
            -- Create a new humanoid object
            local newHumanoid = Instance.new("Humanoid")
            newHumanoid.Name = "Humanoid"
            newHumanoid.Health = humanoid.Health
            newHumanoid.MaxHealth = humanoid.MaxHealth
            newHumanoid.WalkSpeed = humanoid.WalkSpeed
            newHumanoid.JumpPower = humanoid.JumpPower
            newHumanoid.Velocity = humanoid.RootPart.Velocity
            newHumanoid.MoveTo = humanoid.MoveTo
            newHumanoid.AutoRotate = humanoid.AutoRotate
            newHumanoid.Team = humanoid.Team
            newHumanoid.PlatformStand = humanoid.PlatformStand
            newHumanoid.RootPart = humanoid.RootPart
    
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(2)
            torso.Anchored = false
    
            newHumanoid.Parent = character
        else
            print("Character is not an R6 model.")
        end
    end
    

    Now, instead of using the MoveDirection property, the code transfers the player's movement direction by assigning the velocity of the humanoid's root part to the new humanoid object.

    I hope this updated code works better for you!

  23. User

    now it gives me this error "Velocity is not a valid member of Humanoid "Humanoid""

  24. Assistant

    I apologize for the mistake. It turns out that the Velocity property is not a member of the Humanoid object, as I mentioned previously - it's actually a member of the Part object.

    Instead of assigning the Velocity property of the Humanoid object, you can instead assign it to the RootPart property of the player's character model. Here's the updated code:

    local function ragdollPlayer(player)
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:FindFirstChildOfClass("Humanoid")
    
        if humanoid.RigType == Enum.HumanoidRigType.R6 then
            local ragdoll = humanoid:FindFirstChild("Ragdoll")
            local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
            
            if not ragdoll then
                print("Ragdoll object not found in humanoid.")
                return
            elseif character:FindFirstChild("Ragdoll") then
                print("Character is already ragdolled.")
                return
            end
    
            -- Create a new humanoid object
            local newHumanoid = Instance.new("Humanoid")
            newHumanoid.Name = "Humanoid"
            newHumanoid.Health = humanoid.Health
            newHumanoid.MaxHealth = humanoid.MaxHealth
            newHumanoid.WalkSpeed = humanoid.WalkSpeed
            newHumanoid.JumpPower = humanoid.JumpPower
            newHumanoid.MoveTo = humanoid.MoveTo
            newHumanoid.AutoRotate = humanoid.AutoRotate
            newHumanoid.Team = humanoid.Team
            newHumanoid.PlatformStand = humanoid.PlatformStand
            newHumanoid.RootPart = humanoid.RootPart
    
            local rootPart = character:FindFirstChild("HumanoidRootPart") or character:FindFirstChild("LowerTorso")
            rootPart.Velocity = humanoid.RootPart.Velocity
    
            humanoid:Destroy()
            ragdoll:Clone().Parent = character
            
            torso.Anchored = true
            wait(2)
            torso.Anchored = false
    
            newHumanoid.Parent = character
        else
            print("Character is not an R6 model.")
        end
    end
    

    Now, instead of setting the Velocity property of the Humanoid object, the code finds the HumanoidRootPart of the player's character model and sets its Velocity property to the value of the original humanoid's root part's Velocity.

    I apologize for any confusion my previous message may have caused. Thank you for bringing this to my attention!

  25. User

    dont worry! i am just trying to make a soccer game and i wanted for it to ragdoll when a goalkeeper dives, it also gave me this problem "MoveTo is not a valid member of Humanoid "Humanoid""

  26. Assistant

    I apologize for another mistake