So I am new to scripting and I am trying to do something, how do I eliminate all NPC once it hits the timer, for example, how do I make a timer like 1min, then it will kill all npc?
use wait and also For loop,I cannot send you the script rn since I donot know where you place your npc so could you please send where you keep your npc?
Everytime an npc is created, you could assign a tag to its humanoid via collectionservice, and then when the timer hits zero, use a for loop to loop through every tagged humanoid and kill them
Edit: i did not mean to reply to @tin_nim
Try this:
for i = 1,60 do
print("a second has passed!")
task.wait(1)
end
for i,v in ipairs(workspace:GetChildren()) do
if v.Name == "NPC" then
v:Destroy()
end
end
Haven’t tested it, so I’m not sure if the 1 minute timer I made is accurate.
this won’t work if his npc’s arent named “NPC”, in any case where you want to organize npc’s by name or if your npc’s are parented to a different location
How abt
for i = 1,60 do
print("a second has passed!")
task.wait(1)
end
for i,v in ipairs(workspace:GetChildren()) do
if v:FindFirstChildOfClass("Humanoid") then
if game.Players:GetPlayerFromCharacter(v) == nil then
v:Destroy()
end
end
end
Yes, I am aware of that. He can just change the string to the names of his NPC. You could also just add a tag that’s only inserted inside NPCs (if you want), like for example:
for i = 1,60 do
print("a second has passed!")
task.wait(1)
end
for i,v in ipairs(workspace:GetChildren()) do
local tag = v:FindFirstChild("NPCTag", true)
if tag then
v:Destroy()
end
end
you would never find a Humanoid to be the direct child of the workspace, you have to have the specific location of your npc’s humanoid while ignoring the humanoid of valid players
Thank u guys, I will try some suggestions