My startercharacter script
local replicatedStorage = game:GetService("ReplicatedStorage")
local limbDamageEvent = replicatedStorage:WaitForChild("LimbDamage")
-- Health values for limbs
local limbHealth = {
["Left Arm"] = 50,
["Right Arm"] = 50,
["Left Leg"] = 50,
["Right Leg"] = 50
}
-- Table to track health of player limbs
local playerLimbHealth = {}
-- Listen to the RemoteEvent
limbDamageEvent.OnServerEvent:Connect(function(player, enemyCharacter, limbName)
if not playerLimbHealth[enemyCharacter] then
playerLimbHealth[enemyCharacter] = {
["Left Arm"] = 50,
["Right Arm"] = 50,
["Left Leg"] = 50,
["Right Leg"] = 50
}
end
-- Decrease limb health
playerLimbHealth[enemyCharacter][limbName] = playerLimbHealth[enemyCharacter][limbName] - 10 -- Adjust damage amount here
-- When health is zero, detach the limb and add gibs
if playerLimbHealth[enemyCharacter][limbName] <= 0 then
local limb = enemyCharacter:FindFirstChild(limbName)
if limb then
-- Add gibs and destroy the limb
local gib = replicatedStorage.Gibs:FindFirstChild(limbName .. "Gib"):Clone()
gib.CFrame = limb.CFrame
gib.Anchored = true -- Ensure gibs are anchored to the ground
gib.Parent = workspace -- Add gibs to the workspace
-- Destroy the limb
limb:Destroy()
-- Prevent the limb from being detached again by setting health to zero
playerLimbHealth[enemyCharacter][limbName] = 0
end
end
end)
And my server script
local replicatedStorage = game:GetService("ReplicatedStorage")
local limbDamageEvent = replicatedStorage:WaitForChild("LimbDamage")
-- Health values for limbs
local limbHealth = {
["Left Arm"] = 50,
["Right Arm"] = 50,
["Left Leg"] = 50,
["Right Leg"] = 50
}
-- Table to track health of player limbs
local playerLimbHealth = {}
-- Listen to the RemoteEvent
limbDamageEvent.OnServerEvent:Connect(function(player, enemyCharacter, limbName)
if not playerLimbHealth[enemyCharacter] then
playerLimbHealth[enemyCharacter] = {
["Left Arm"] = 50,
["Right Arm"] = 50,
["Left Leg"] = 50,
["Right Leg"] = 50
}
end
-- Decrease limb health
playerLimbHealth[enemyCharacter][limbName] = playerLimbHealth[enemyCharacter][limbName] - 10 -- Adjust damage amount here
-- When health is zero, detach the limb and add gibs
if playerLimbHealth[enemyCharacter][limbName] <= 0 then
local limb = enemyCharacter:FindFirstChild(limbName)
if limb then
-- Add gibs and destroy the limb
local gib = replicatedStorage.Gibs:FindFirstChild(limbName .. "Gib"):Clone()
gib.CFrame = limb.CFrame
gib.Anchored = true -- Ensure gibs are anchored to the ground
gib.Parent = workspace -- Add gibs to the workspace
-- Destroy the limb
limb:Destroy()
-- Prevent the limb from being detached again by setting health to zero
playerLimbHealth[enemyCharacter][limbName] = 0
end
end
end)