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!