I'm currently making an FPS/Survival game. I made a Script just for the NPC. To follow the player, to attack when close. I want it so that when the NPC dies, its limbs, torso, and head will be removed after a few seconds. Here's the script.
function onDeath() local mobmodel = script.Parent if mobmodel.Zombie.Health > 1 then wait(3) mobmodel:remove() else end mobmodel.Zombie.Health.Changed.connect(onDeath)
Am I missing something? Do I need to change something?
Hello,
I assume you are new to RbxLua,I will try to help as far as I can.
local d = game:GetService("Debris") -- A service to remove stuff , like a bin. local mobmodel = script.Parent -- Variables are declared outside of local functions. mobmodel.Zombie.Humanoid.Died:connect(function()--A Humanoid.Died(function) is better than checking the health everytime it changes. --Stuff you want. d:AddItem(mobmodel,2) -- Removes the part after 2 seconds. end) -- Also do not forget to end loops and functions appropriately.
I am still learning RbxLua.
Thank you for reading.