#Why is there no delay in this loop?
1 messages · Page 1 of 1 (latest)
how do i fire it a single time? The zone is just a giant translucent red part
ok ty i havent scripted ina hot minute
whats your goal
uhm, well im using print just to get the delay working, but essentially its an enemy system that will maintain 5 enemies even if they are killed
fire pfp btw
still fire
yeah, i also do plan to detect a touch end so it will despawn everything when you leave the zone
i thought touch was just a single detection
use clickdetector
use ClickDetector, connect to the clicked event, set a variable to true
use while loop below that even
while task.wait(1) do
if enabled then
bla bla
end
end
oh when you entered the zone
aight
create a variable for enabling/disabling purpose, use touched for setting the variable to true, use touchended to set it to false
create a while loop after those events using the same code i sent above
im very beginner if u couldnt tell already, but I kinda got it to work, except instead of spawning 5, and then waiting to spawn another once one dies, it spawns 3 and then despawns all of them
local enemynum = 0
local storage = script.Parent.Parent.current
local inzone = false
script.Parent.Touched:Connect(function()
inzone = true
end)
script.Parent.TouchEnded:Connect(function()
inzone = false
end)
while task.wait(1.5) do
if inzone == true and enemynum <= 5 then
local enemy = game.ServerStorage.enemy:Clone()
enemy.Parent = storage
enemynum = enemynum+ 1
elseif inzone == false then
storage:ClearAllChildren()
end
end
thats because the first mob that gets spawned in triggers the TouchEnded
which in turn triggers the storage:ClearAllChildren()
are you trying to do something like
if there are 5 mobs in the area than it stops, but if there are 5 mobs and one is outside the area, than it continues spawning?
kinda like a minecraft spawner
i would recommend instead of inzone being a true or false, you can make it into a list that adds the enemies to it, and if they walk out the zone, you remove them from the list
lists come with a count feature too so you dont need the enemynum variable
no, the despawning was for if the player leaves the zone, the enemies despawn
