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