Model not being recognised in module script loop

I have a module script that acts as a service of being a “Ragdoll service” and one of its major functions is to build collision parts by looping through the base parts inside of the player’s character however, it returns an error of

ReplicatedStorage.Services.RagdollService:12: attempt to call missing method 'GetDescendants' of table  -  Server - RagdollService:12

the extract this error in my module script is,

function RagdollService.BuildCollisionParts(character : Model)
     for index, child in ipairs(character:GetDescendants()) do
          if child:IsA("BasePart") and child.Name ~= "HumanoidRootPart" then
               local ColPart = child:Clone()
               ColPart.CollisionGroup = "Ragdoll"
               ColPart.Parent = child
               ColPart.CanCollide = true
               ColPart.Massless = true
               ColPart.Size = Vector3.one
               ColPart.Transparency = 1
               ColPart:ClearAllChildren()
               
               local Weld = Instance.new("Weld")
               Weld.Parent = ColPart
               Weld.Part0 = child
               Weld.Part1 = ColPart
          end
     end
end

The error is on the line that says

 for index, child in ipairs(character:GetDescendants()) do

No lines in my code were underlined as red so i can’t find the issue

I’m not entirely sure what the “Missing method” is as I had used the get descendants function, any help would be appreciated

the passed argument might be the wrong type (a table?)

try printing character before the loop and see what you get

I have tried this and it prints me

  17:00:26.993  table: 0xc55cac32da1bf2ac  -  Server - RagdollService:12

seems like its a table
can you share the script that calls the function from the module?

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local RagdollService = require(game.ReplicatedStorage.Services.RagdollService)

Humanoid.Died:Connect(function()
     RagdollService.RagdollCharacter(Character)
end)

Its a server script inside of starter character scripts

I also have a script to modify the humanoid properties and it works
no errors are outputted

player.CharacterAdded:Connect(function(character)   
     local Humanoid = character:WaitForChild("Humanoid")
     RagdollService.SetUpHumanoid(character)
end

Character here is a model so thats fine, tho its passed in RagdollService.RagdollCharacter, which i assume uses RagdollService.BuildCollisionParts

If so, can you send RagdollCharacter()'s code?

function RagdollService.RagdollCharacter(character : Model)
     local Humanoid = character:WaitForChild("Humanoid")
     local HRP = character:WaitForChild("HumanoidRootPart")
     local RagdollAttribute = Humanoid:GetAttribute("Ragdoll")
     
     if RagdollAttribute == nil then
          local RagdollAttribute = Humanoid:SetAttribute("Ragdoll", true)
     end
     
     RagdollAttribute = true
     
     RagdollService:BuildCollisionParts(character)
     RagdollService:BuildJoints(character)
     RagdollService:EnableMotor6D(character, false)
     
     Humanoid.AutoRotate = false
     Humanoid.PlatformStand = true
end

Do some debugging, how are you passing a table.

Check to see if you’re passing a model:

function RagdollService.BuildCollisionParts(character)
    if typeof(character) ~= "Instance" or not character:IsA("Model") then -- check here
        warn("RagdollService Error: 'character' is not a valid Model!", character)
        return
    end

    for index, child in ipairs(character:GetDescendants()) do
        if child:IsA("BasePart") and child.Name ~= "HumanoidRootPart" then
            local ColPart = child:Clone()
            ColPart.CollisionGroup = "Ragdoll"
            ColPart.Parent = child
            ColPart.CanCollide = true
            ColPart.Massless = true
            ColPart.Size = Vector3.one
            ColPart.Transparency = 1
            ColPart:ClearAllChildren()
            
            local Weld = Instance.new("Weld")
            Weld.Parent = ColPart
            Weld.Part0 = child
            Weld.Part1 = ColPart
        end
    end
end
local RagdollService = require(game.ReplicatedStorage.Services.RagdollService)
local character = game.Players:GetPlayerFromCharacter(script.Parent) and script.Parent

if character and character:IsA("Model") then
    RagdollService.BuildCollisionParts(character)
else
    warn("Character is not a valid Model!")
end

also before calling the function print the character type:

print("Character Type:", typeof(character), character)
1 Like

It does recognise it as an instance however it also warns

17:23:56.889  RagdollService Error: 'character' is not a valid Model! table: 0xdf418c73beac8bae  -  Server - RagdollService:38

Im not really sure why it both recognises it as an instance and a table

Try to print the type of the character in the .RagdollCharacter function.

I already did and it returns

  17:38:23.074  Character Type: Instance fartpants007  -  Server - RagdollService:78

Show me your character children (the explorer window) in play mode

image

Wait, I just thought of something. Hover over the RagdollService functions you call in RagdollCharacter, do they have a self param or similar? If not im gonna have to rebuild your module script from scratch.

Ah, that explains it!
You do this:

 RagdollService:BuildCollisionParts(character)

using the colon notation it implicitly passes ragdollservice as self.
Because your BuildCollisionParts function is declared with the . notation, its self will be nil and when called with the colon notation the self will be the first argument, so basically you’re calling it like this:

RagdollService.BuildCollisionParts(RagdollService, character)

and obviously RagdollService is not of type Model!
So, simple fix, replace the colon with a dot:

RagdollService.BuildCollisionParts(character)

or alternatively, if you like the colon notation, define the function like this:

function RagdollService:BuildCollisionParts(character)--with colon
end

--or like this:
function RagdollService.BuildCollisionParts(self: table, character: Model)--dot but specify self as a parameter.
end

this should fix your issue, hope this helps!

1 Like

i’m just gonna give you the function

function RagdollService.RagdollCharacter(character : Model)
     print("Character Type:", typeof(character), character)
     
     local Humanoid = character:WaitForChild("Humanoid")
     local HRP = character:WaitForChild("HumanoidRootPart")
     local RagdollAttribute = Humanoid:GetAttribute("Ragdoll")
     
     if RagdollAttribute == nil then
          local RagdollAttribute = Humanoid:SetAttribute("Ragdoll", true)
     end
     
     RagdollAttribute = true
     
     RagdollService:BuildCollisionParts(character)
     RagdollService:BuildJoints(character)
     RagdollService:EnableMotor6D(character, false)
     
     Humanoid.AutoRotate = false
     Humanoid.PlatformStand = true
end

Try to replace

RagdollService:BuildCollisionParts(character)
RagdollService:BuildJoints(character)
RagdollService:EnableMotor6D(character, false)

the “:” with “.”

RagdollService.BuildCollisionParts(character)
RagdollService.BuildJoints(character)
RagdollService.EnableMotor6D(character, false)

Yep thats 100% the issue, replace “:” with “.”

isnt that the same symbol?
It looks the same to me

1 Like