Its supposed to summon an enemy every other second, until there's 5, or until they leave the zone, (This script is inside the zone they need to be touching.) But if they leave the zone, and come back, it should still be able to summon. What am I doing wrong?
local storedenemy = game.ServerStorage.enemy
local enemy = storedenemy:Clone()
local currentenemys = 0
script.Parent.Touched:Connect(function(Player)
local humanoid = Player.Parent:WaitForChild("Humanoid")
while true do
if humanoid then
repeat
enemy.Parent = workspace.field.current
currentenemys +=1
wait(1)
until currentenemys == 5
end
end
end)
Im VERY beginner so don't chuckle.