Module won't run

I already have the scripts,but the problem is that i don’t know much about modules.Therefore,my module can have some bugs.First of all,here is the deathhandler

local PlayerService = game:GetService("Players")

local function WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
	Humanoid.Died:Connect(function()
		print("Death event triggered")
		local Module = script:FindFirstChild(DeathEquipped.Value)
		print(DeathEquipped.Value)
		if Module then
			print("Module found")
			local success, err = pcall(function()
				require(Module).PlayDeathEffect(Character)
			end)
			if success then
				print("Death effect played successfully")
			else
				print("Error playing death effect: ", err)
			end
		end
	end)
end

local function SetupPlayer(Player)
	local DeathEquipped = Instance.new("StringValue")
	DeathEquipped.Name = "DeathEquipped"
	DeathEquipped.Value = "Ragdoll"
	DeathEquipped.Parent = Player

	local function onCharacterAdded(Character)
		local Humanoid = Character:WaitForChild("Humanoid", 300)
		WaitForCharacterDeath(Character, Humanoid, DeathEquipped)
	end

	Player.CharacterAdded:Connect(onCharacterAdded)

	if Player.Character then
		onCharacterAdded(Player.Character)
	end
end

PlayerService.PlayerAdded:Connect(function(NewPlayer)
	task.spawn(SetupPlayer, NewPlayer)
end)

And here is the example of my module

local Ragdoll = {}

function Ragdoll.PlayDeathEffect(Character)
	local humanoid = Character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
        humanoid:ChangeState(Enum.HumanoidStateType.Physics)
        
        for _, part in Character:GetChildren() do
            if part:IsA("BasePart") then
                part.CanCollide = true
                part.Anchored = false
            end
        end
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Character)
        local humanoid = Character:WaitForChild("Humanoid")
        humanoid.Died:Connect(function()
			Ragdoll.PlayDeathEffect(Character)
        end)
    end)
end)

return Ragdoll

Hope i can find help here!

1 Like

Does the ‘Death effect played successfully’ print?

yes,it is the problem with the module itself

Print Humanoid inside of the module, what does it print?

it seems to print humanoid,so the problem is further in the script

1 Like

Could try to print out the part that got looped though, and that game.players.playeradded will never run because module only run the code that is refenced so the ragdoll wil but not game.players

local Ragdoll = {}

function Ragdoll.PlayDeathEffect(Humanoid)
	for index, joint in pairs(script.Parent:GetDescendants()) do
		print("eeqweqwes")
		if joint:IsA("Motor6D") then
			print("success")
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end

return Ragdoll

I’ve revamped the script,and it seems,that the first print prints,and the second print doesn’t,what is the problem?

Where is this script located? Also you can search though the humanoids parent and get a diffident chance it will be a joint when checking.

the script is located in the deathhandler(the server script)

So your issue here is that your checking your sever script if itt has a joint which of course it wouldn’t so need to search the humanoid parents descendants so if look like

for i, joint in humanoid.parent:GetDescendants() do
-- rest of ragdoll script
end

And that should be your problem with the script

i did exactly what you said,and here is the issue (Part0 is not a valid member of Part “Workspace.Players.DemidPlay1238.Head”)

nevermind,i really fixed it myself

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.