So basically, I have a script here that manages the destroyed / attacked npcs for my simulator. But, the thing is is that while another npc is destroyed and a player attemps to destroy another npc, the npc that the player is trying to destroy doesn’t work unless they wait 25 seconds for the other npc to be spawned in again. By the wait, the script is in a local script.
task.spawn(function()
while task.wait(1) do
if player.Values.SentTo.Value ~= nil then
local damage = 10
player.Values.SentTo.Value.Health.Value = math.max(player.Values.SentTo.Value.Health.Value - damage, 0)
game.ReplicatedStorage.Assets.SoundEffects["Scythe Swish"]:Play()
player.Values.SentTo.Value.Highlight.Enabled = true
wait(0.2)
player.Values.SentTo.Value.Highlight.Enabled = false
if player.Values.SentTo.Value.Health.Value == 0 then
remotes.StopDamaging:FireServer()
destroyDrop(player.Values.SentTo.Value)
end
end
end
end)
Destroy drop function
local function destroyDrop(drop)
task.wait(0.5)
local oldParent = drop.Parent
for i = 0,37 do
wait(.01)
drop.MainPart.Transparency += .05
end
drop.Parent = despawnedDrops
wait(25)
drop.MainPart.Transparency = 0
drop.Health.Value = drop.MaxHealth.Value
drop.Parent = oldParent
end