Peds spawn problem

I need some help here with NPC/Peds spawn

When i trigger this : CreatePed(4, 0x22911304, 122.702, -1308.935, 29.227, 0, false, true)
it spawns a ped for every player thats online, is there a way to only spawn 1 ped that every online player can see?

If you look at the code signature of CREATE_PED…

Ped CREATE_PED(int pedType, Hash modelHash, float x, float y, float z, float heading, BOOL isNetwork, BOOL thisScriptCheck);

You will notice that it has an “isNetwork” flag. Since you are always setting that to false, there is no way that ped gets send over the network.

even if i put that on true it still spawns a npc pr user, i use this to trigger the spawn could this be the reason?
TriggerClientEvent(“test:test”, -1)

So ALL the clients spawn that ped? Are you using the server to send an event to the client to spawn that ped?

Yes i´am, and thats the reason why it spawns 1 for every player online

Then you probably need some logic to prevent this from happening, what would be conditions that a client must spawn a ped?

I have a timer that that runs every 1 min (Test purpose), my plan is that i want a npc to change location every once a while, but right now the problem is that it spawns one pr player online.

So that question is is there a work around so it will only spawn 1 npc for the whole server.

Trigger the client event to only 1 player, not every player

Then other players wont be able to see the npc

Like he said, just put “isNetwork” to true and other player will see it

Hi Sir , did you know how to remove PED if the player disconnected , because on my server if player disconnected player character become ped

Enable onesync and the player ped will disappear on disconnect.