I need help on discovering how to make a script that, when an npc dies, after it ragdolls, a copy of it gets made, that way it doesn’t despawn, i already got a script for the ragdoll.
Something like this i guess
local ragdollModule = require(...)
local character = script.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local fuction died()
local clone = character:Clone()
clone.Parent = workspace
character:Destroy()
ragdollModule:ragdoll(clone)
task.delay(30, function()
clone:Destroy()
end)
end)
humanoid.Died:Connect(died)
Try this, put this script into the NPC, and then make a copy of the NPC in ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local npc = ReplicatedStorage:WaitForChild(script.Parent.Name)
script.Parent.Humanoid.Died:Connect(function()
local newNPC = npc:Clone()
newNPC:PivotTo(script.Parent:GetPivot()) --Remove this if you dont want it to respawn at current NPC location
task.wait(5) --Remove this if you don't want a wait
newNPC.Parent = game.Workspace
script.Parent:Destroy()
end)
This is literally worse than my script
1 Like
Tried using the script both in the npc and in serverscriptservice, but after the npc dies the ragdoll disappears anyways, did i do something wrong?
If you literally copied the script ofc it wont work, you need to add your own ragdoll module to it, or if you prever using scripts try this:
NPC
- Ragdoll script (disabled)
- Death script (enabled)
Then if the NPC dies, you clone it and enable the ragdoll script.
1 Like
Well I can revise yours so it atleast works
--ragdollModule doesn't do anything
local character = script.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local function died() --Changed "fuction" to "function" so it works
local clone = character:Clone()
clone:FindFirstChildOfClass("Humanoid").Health = 100 --The clone will spawn dead if this line doesnt exist
clone.Parent = workspace --This will make the clone spawn immediately after death, move it right before character:Destroy() if you want the delay
--character:Destroy() destroys the parent of this script, we don't need this yet
--ragdollModule doesn't do anything
task.delay(30, function()
character:Destroy() --Now we destroy character (unless you want the clone destroyed)
end)
end --Removed the unnecessary ")"
humanoid.Died:Connect(died)
An I can actually revise my own script!
local npc = script.Parent
script.Parent.Humanoid.Died:Connect(function()
local newNPC = npc:Clone()
newNPC:FindFirstChild("Humanoid").Health = 100
newNPC:PivotTo(script.Parent:GetPivot()) --Remove this if you dont want it to respawn at current NPC location
task.wait(5) --Remove this if you don't want a wait
newNPC.Parent = game.Workspace
script.Parent:Destroy()
end)
1 Like
Ok thank you, I write all my scripts on mobile so I never test them
1 Like