As in the title, its clear.
To be clear, the respawning of a NPC occurs in a tool, cause if i put a normal script inside the NPC, it doens’t work for some reason.
What is happening is that everytime the NPC respawns, it stops completely with the Script, Animations, Health and others. I wanna know if there is a way to me apply a normal script that revives the npc, and the scripts works. Or if i can fix the respawn script that is inside the tool.
The tool script:
local Tool = script.Parent
local Handle = Tool:FindFirstChild("Handle")
local SwordStatus = Tool:FindFirstChild("SwordStatus")
local StatusModule = require(SwordStatus)
local PlayerService = game:GetService("Players")
local LocalPlayer = PlayerService.LocalPlayer
local AniamtionsTable = StatusModule.AnimationTable
local SoundEffectTable = StatusModule.SoundeffectTable
local SoundEffect = Handle:FindFirstChild("SoundEffect")
local IsAttacking = false
local Debounce = false
Tool.Activated:Connect(function()
local RandomIndex = math.random(1, #SoundEffectTable)
local RandomSound = SoundEffectTable[RandomIndex]
SoundEffect.SoundId = RandomSound
SoundEffect:Play()
end)
Tool.Activated:Connect(function()
IsAttacking = true
task.wait(StatusModule.Damage)
Debounce = false
IsAttacking = false
end)
Handle.Touched:Connect(function(Hit)
local EnemyCopy = Hit.Parent:Clone()
local Enemy = Hit.Parent
local ChaseScript = Hit.Parent:FindFirstChild("ChaseScript")
local ChaseScriptCopy = ChaseScript
local Humanoid
for i,v in pairs(Enemy:GetChildren()) do
if v:IsA("Humanoid") then
Humanoid = v
end
end
if Humanoid then
if Humanoid.Health <= 0 then
task.wait(2.5)
EnemyCopy.Parent = Enemy.Parent
EnemyCopy:MakeJoints()
Enemy:Destroy()
ChaseScriptCopy.Parent = ChaseScript.Parent
ChaseScriptCopy:Clone()
ChaseScript:Destroy()
if EnemyCopy:FindFirstChildWhichIsA("Humanoid").Health <= 0 then
EnemyCopy:FindFirstChildWhichIsA("Humanoid").Health = EnemyCopy:FindFirstChildWhichIsA("Humanoid").Health + 100
end
end
else
warn("Cannot find Humanoid in Respawn Script!")
end
end)
Handle.Touched:Connect(function(Hit)
if IsAttacking and Hit.Parent:FindFirstChild(StatusModule.HumanoidToDamage) and Hit.Parent:FindFirstChild(StatusModule.HumanoidToDamage):IsA("Humanoid") then
if not Debounce then
Debounce = true
Hit.Parent:FindFirstChild(StatusModule.HumanoidToDamage):TakeDamage(StatusModule.Damage)
task.wait(StatusModule.Cooldown)
Debounce = false
local EnemyHumanoidRootPart = Hit.Parent:FindFirstChild("HumanoidRootPart")
if Hit.Parent:FindFirstChild(StatusModule.HumanoidToDamage).Health <= 0 and EnemyHumanoidRootPart ~= nil then
Hit.Parent:FindFirstChild("HumanoidRootPart"):Destroy()
end
end
end
end)