#Enemy wave spawner. For loop no looping

1 messages · Page 1 of 1 (latest)

tight magnet
#

Hi everyone. I am following a tutorial https://youtu.be/U2Hy1R-qgBw?si=lIXEx06HyLTF49yt going about making enemy waves.
The code for the loop is proved in a ss and the other ss is the prints in the terminal(the one from enemy logic are just its stats and are irrelevant to this problem)

How to Make a Tower Defence Game in Roblox Studio | Part 2 | Wave Spawning

-- Welcome to Driple Studios! --
We’re here to help you become a game developer, one tutorial at a time. Whether you’re new to game development or looking to level up your skills, our videos are crafted with beginners in mind.

-- In This Video --
Joe continues his n...

▶ Play video
#

So what this loop essentially does is it itterates through the wave.enemyCount and spawns enemies for every itteration. After each spawn it halts a set number of seconds before spawning the next, in this case 1 second, but it only spawns one singular enemy and as you can see; Both the enemyCount and the delay aren't set weirdly. The delay is just one second and the enemyCount is 5 meaning it should repeat five times. Although I do think the wait is messing with it as the print after the wait does not get fired at all.

#

Can someone please help me out here 😅

sharp orbit
#

for i=math.huge()

#

try that and see if it changes

tight magnet
#

output says "stack begin
stack end"

sharp orbit
#

i=1000 maybe

#

im just thinking it wants to reach 1 by 5 increments

tight magnet
sharp orbit
#

maybe i=1, 5, .1

tight magnet
#

as the print after the wait doesnt get fired

sharp orbit
#

could the enemy script be breaking the loop?

#

put the local variable outside of the loop and see what it does

tight magnet
#

as this variable is dependened on the local enemy clone

#

@sharp orbit It seems the loop just stops after calling the startmoving()

#

as all the prints before this Start_Moving() line fire

sharp orbit
#

oh actually just wrap it in a coroutine

tight magnet
sharp orbit
#

its probably just running the function and waiting for it to end maybe

#

possiblu

tight magnet
tight magnet
#

How do I make a co routine?

stoic sentinel
tight magnet
#

Haha ur fine

sharp orbit
#

coroutine.resume(coroutine.create(function()
--functions
end))

#

thats how i use it

stoic sentinel
sharp orbit
#

but i use older versions of roblox studio so im not sure whats better

tight magnet
sharp orbit
#

but im not sure if they know how

tight magnet
#

Nope

#

Not a clue

stoic sentinel
tight magnet
#

I’m like a toddler when it comes to Luau yet

stoic sentinel
tight magnet
tight magnet
stoic sentinel
#

just use rigs with no humanoids, make sure they have an animation controller and an animator for animating them, you can keep their humanoid root part anchored and calculate their movement each frame which would be much way better than humanoids since those little shits can fuck your performance if there are a lot of them

#

I have an example code I use in my game, it might be a bit complicated but I can send it if you want

stoic sentinel
#

lemme find it real quick

stoic sentinel
tight magnet
#

Like
Local part: part = script.parent

stoic sentinel
#

well I have the enemies movement in typescript as organized code, I also have in luau but a bit messy

tight magnet
#

Then I don’t think I know what typescript is

#

What is it?

stoic sentinel
#

a programming language

#
-- server
local enemyMovement = function()
    for entity, _, progress, speed in query do
        local pathLength = BezierPath.PathLength
        local step = speed / pathLength
        local newProgress = progress + step * scheduler:getDeltaTime()
        if newProgress >= 1 then
            --TODO: base damage
            world:delete(entity)
            continue
        end
        local newTransform = BezierPath:CalculateUniformCFrame(newProgress)
        world:set(entity, Components.enemyProgress, newProgress)
        world:set(entity, Components.transform, newTransform)
        if world:has(entity, Tags.EnemyDebugVisual) then
            local character = world:get(entity, Components.character)
            if character then
                character:PivotTo(newTransform)
            end
        end
    end
end```
#

here is the luau version

#

it runs every frame to move the enemies on a pre-computed path

#
-- client
local enemyMovement = function()
    for entity, _, progress, speed, character in query do
        local isAir = world:has(entity, Tags.Air)
        --/ getting distance travelled per second based on enemy speed and total path length
        local step = speed / pathLength
        --/ multyplying by delta time since the system runs every frame
        local newProgress = progress + step * scheduler:getDeltaTime()
        if newProgress >= 1 then
            --/ delete enemy if he reached the end
            world:delete(entity)
            continue
        end
        --/ caching the Y position based on the model height if it doesn't exist
        local _name = character.Name
        if not (CachedYPositions[_name] ~= nil) then
            local _name_1 = character.Name
            local _arg1 = Utils.GetConstantYPosition(true) + character:GetExtentsSize().Y * 0.55
            CachedYPositions[_name_1] = _arg1
        end
        --/ setting new transform based on the new progress
        local newTransform = BezierPath:CalculateUniformCFrame(newProgress)
        local _exp = newTransform.X
        local _name_1 = character.Name
        local _cFrame = CFrame.new(_exp, (CachedYPositions[_name_1]) + (if isAir then 10 else 0), newTransform.Z)
        local _rotation = newTransform.Rotation
        newTransform = _cFrame * _rotation
        --/ setting component values
        world:set(entity, Components.enemyProgress, newProgress)
        world:set(entity, Components.transform, newTransform)
        character:PivotTo(newTransform)
    end
end```
#

it has some hard coded bits since it is a prototype that's only an idea for now

pale granite
#

Could you send the whole script u got pls?

sharp orbit
#

its like telling a baby the secrets to the universe

stoic sentinel
sharp orbit
#

i dont think theyre gonna understand that

stoic sentinel
# sharp orbit its like telling a baby the secrets to the universe

well I did state that it may be a bit complicated to understand, but the logic should be understandable since they do have experience with programming in general and other game engines, it is just making a path that has a progress 0-1 and using that path to calculate how long is each step

pale granite
stoic sentinel
pale granite
#

Gosh I meant the post owner

stoic sentinel
#

if you were talking to him you should have replied to their message or pinged them, as the last message was sent by me I assumed you were talking to me

stoic sentinel
pale granite
#

Ok