So i have a script that is parented to a Monster model. The problem is after i destroy the monster its script keeps on running and keeps spawning some Blast attack even if i coudn’t see any script on the workspace.
local Npc = script.Parent
local zombieHumanoid = script.Parent:FindFirstChild("Humanoid")
local animation = script:FindFirstChildOfClass("Animation")
local walkAnimation = script:FindFirstChild("walkAnimation")
local laughAnimation = script:FindFirstChild("LaughAnimation")
local animator = zombieHumanoid:FindFirstChildOfClass("Animator")
local animationTrack = animator:LoadAnimation(animation)
local walk = animator:LoadAnimation(walkAnimation)
local laugh = animator:LoadAnimation(laughAnimation)
local zombieHRP = script.Parent:FindFirstChild("HumanoidRootPart")
local module = require(game.ServerStorage["MuchachoHitboxV1.1"])
local SmahSound = script:FindFirstChild("Sound")
local power = game.ServerStorage.power
local blast = game.ServerStorage.Blast
local hitbox = module.CreateHitbox()
local db = false
walk:Play()
local function findTarget()
local distance = 500
local target = nil
for i,v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local HumanoidRootPart = v:FindFirstChild("HumanoidRootPart")
if human and HumanoidRootPart and v ~= script.Parent and human.Health > 0 then
if(zombieHRP.Position- HumanoidRootPart.Position).Magnitude < distance then
distance = (zombieHRP.Position- HumanoidRootPart.Position).Magnitude
target = HumanoidRootPart
if distance < 80 and not db then
db = true
animationTrack:Play()
SmahSound:Play()
local powerclone = power:Clone()
local blastclone = blast:Clone()
powerclone.Parent = game.Workspace
blastclone.Parent = game.Workspace
powerclone.Position = zombieHRP.Position + Vector3.new(0,-68,0)
blastclone.Position = zombieHRP.Position + Vector3.new(0,-68,0)
hitbox.Size = Vector3.new(5,5,5)
hitbox.CFrame = powerclone
for i=1,10,1 do
hitbox.Size = hitbox.Size + Vector3.new(13,8,13)
end
for i=1,10,1 do
task.wait(0.001)
blastclone.Size = blastclone.Size + Vector3.new(13,0,13)
end
hitbox.Touched:Connect(function(hit,hum)
if hum.Parent.Name ~= "Monster" then
hum:TakeDamage(50)
end
end)
hitbox:Start()
task.wait(0.5)
blastclone:Destroy()
hitbox:Stop()
walk:Stop()
laugh:Play()
task.wait(4)
powerclone:Destroy()
db = false
walk:Play()
laugh:Stop()
end
end
end
end
if zombieHumanoid.Health <= 0 then
script.Disabled = true
Npc:Destroy()
end
return target
end
while wait(1) do
local HumanoidRootPart = findTarget()
if HumanoidRootPart then
zombieHumanoid:MoveTo(HumanoidRootPart.Position)
else
zombieHumanoid:MoveTo(zombieHRP.Position + Vector3.new(math.random(-50,30),0,0))
end
end
![image|666x500]
robloxapp-20221117-1759410.wmv (3.3 MB)