- What do you want to achieve? Keep it simple and clear!
I am trying to make a limb dismemberment script, when a remote is called, the script will first get all the children of the enemy character, then put the limbs of the character into a table. After that, it will kill the enemy character, then it will choose a random number of limbs to dismember, then make them transparent and spawn a clone of the limb.
- What is the issue? Include screenshots / videos if possible!
I keep getting spammed this error:
local BloodSpillRemote = ReplicatedStorage.Remotes.BloodSpillRemote
BloodSpillRemote.OnServerEvent:Connect(function(player, EnemyHumanoid)
local character = EnemyHumanoid.Parent
local limbs = {}
for _, part in pairs(character:GetChildren()) do
if part:IsA("BasePart") and not (part.Name == "HumanoidRootPart" or part.Name == "Head" or part.Name == "Torso" or part.Name == "MeshPart" or part.Name == "Debris") then
if EnemyHumanoid.Health > 0 then
table.insert(limbs, part)
end
end
end
EnemyHumanoid.Health = 0
local numLimbsToDelete = math.random(1, #limbs)
for i=1,numLimbsToDelete do
if limbs[numLimbsToDelete] then --If the limb still exists (it hasn't already been deleted), delete it.
limbs[numLimbsToDelete].Transparency = 1
local fakelimb = limbs[numLimbsToDelete]:Clone()
fakelimb.Parent = limbs[numLimbsToDelete].Parent
fakelimb.CanCollide = true
fakelimb.Transparency = 0
fakelimb.Name = "Debris"
table.remove(limbs, numLimbsToDelete) --Remove the deleted limb from the table so we don't try to delete it again.
end
end
end)
Note:
I used roblox’s new AI tool to write some of the code.