#Understanding task.desynchronize in NPC usecase.

1 messages · Page 1 of 1 (latest)

restive pilot
#

If I use task.desynchronize in a script that is not contained under and actor, what exactly will it do?
I mean I'm just sort of confused by how it works and whatnot
Mainly anything to do with parallel luau just blows up my head
Reason I'm wondering though is because I'm working on a server sided NPC system, and parallel lua article mentions that it is handy for systems including NPCs

#

For example, would this be one usecase

function FindNearestTarget()
task.desynchronize()
-- Code to get nearest Target
  return Target
end

function GoToTarget()
  Target = FindNearestTarget()
  task.synchronize()
  Humanoid:MoveTo(Target.Position)
end
#

The reason being because we can't modify any states in a desynchronized script as the Roblox API states.

indigo harness
#

I am also interested. I'm pr sure its specifically for actors but maybe I'm wrong

restive pilot
restive pilot
#

@opaque scarab any thoughts on this?

#

Since you are experienced with parallel lua

opaque scarab
#

If you call desyncronize without a actor Roblox will give you a error I believe

#

Actors and models are the same so you can replace your NPC model with a actor

opaque scarab
#

Warning?

restive pilot
#

I need to check again

#

but last I tried

#

I'm pretty sure no errors or warnings happened

opaque scarab
#

I remember it giving a error or something for me but it was a long time since I tested

#

It might just ignore the command

restive pilot
#

I hope not

opaque scarab
#

Check the micro profiler to make sure it worked

#

Or one way you find out try changing the name of the NPC while desynchronized

#

If it lets you change the name then it's still synchronized

restive pilot
restive pilot
#

@opaque scarab upon testing this, I didn't get any errors on trying to change the name

#

all it did was do... nothing?

#

The name didn't change

#

but also

#

the scripts execution stopped

#

after the task.desynchronize

#

maybe an error?

#

Wait hold on

restive pilot
#

Yeah it's weird

#

It seems the code execution just stops?

#

Like as if there is an invisible error

opaque scarab
#

i would say report it to roblox but roblox be annoying

restive pilot
#

yea

opaque scarab
#

if you change the npc model to a actor it should start working

#

be warned if you turn the npc to a actor each npc will require a new module npcs will no longer share the same module

#

if your npcs use lots of modules this could increase ram usage

restive pilot
#

BTW, small update to this, calling task.synchronize on a script without an actor will give you a warning now. Likewise for task.desynchronize

weak wadi
weak wadi
# opaque scarab

yeah they have the same properties but i dont think they behave the same since i put all of npcs instances inside an actor and i wasnt able to damage it unlike with a regular model