Targeting "first" is acting weird

I dont know what to do right now, do I add a script in a folder in workspace called system?

Do I keep the module?

How do I modify the module script?

I’ve been trying to fix this glitch for half a year already

Ill be back to check this post in an hour or smt

I hate to break it to you, but if you’ve been consistently adding to a game that’s had this issue for over half a year, you’d be better off just re-writing the whole system to fix it than asking strangers without a deep level of insight into how your game is organized and written, because at this point it’s practically hard-coded into the game.

Oh no, this is the new version with a improved module, its only the module that needs a fix. I made a new template so all it has is the tower and the module and the mob, the module is most most important part of the game as it gets required by the tower script which then the module gives back the mob if found, if no mob was found or the tower was too far from any tower it will return a nil value and the tower checks if the required module returns nil, if it isnt nil it damages the mob by the config dmg.

Hmmm

Maybe something like

local nearestEnemy

for i, enemy in ipairs(enemiesTable) do
    if #enemiesTable > 0 and not nearestEnemy then
        nearestEnemy = enemy
    else
        nearestEnemy = if enemy then nearestEnemy else nil
    end

    if (enemy.Position-tower.Position).Magnitude < (nearestEnemy.Position-tower.Position).Magnitude then
        nearestEnemy = enemy
    end

end

Thats the nutshell script with the Y magnitude (bad idea) and without the “first” target mode

Also the nutshell of the “closest” mode and a basic version of my script, i dont know why roblox is acting this way. Maybe there is a delay on some side or smt?

I’m really unsure what to do.

Like I said, without CollectionService, your game is going to have a difficult time keeping up with things due to all the separate threads running in different scripts.

It sounds like there’s a lot of asynchronous activity happening, objects not communicating with each other in the intended order, hence the nearest enemy constantly changing.

Then again, also like I said, there’s only so much advice I can offer without knowing, in depth, how your game works.

Im also surprised your still willing to help me after this long

Honestly I could send you the game file.

I could help you much better. Contact me on Guilded.

Physically handling, tampering with and attempting to fix someone else’s game files sounds like something best saved for an employee or an intern, imo.

I’m just a forum volunteer sharing what possibly flawed knowledge I have, and I tried lmao

Something tells me this guy is looking for contract work more in the zero digit price range

do you have discord?
Also hold on im gonna send a copy of the game

He wants money, bud. His bio says he’s a contract worker

Oh then nah I dont need workers
anyways here is a copy and how it looks (particle = target)

Didn’t say anything about money, don’t put words in my mouth.

Do you have discord? Or only guided

Guilded is officially owned by Roblox, I prefer Guilded as well, because it’s features are free.

Oh I didnt know that! Ok then, give me a moment ima install guided