How would i go about making client sided npcs?

so i need to make client sided combat npcs

bassically everyone in game would see the client sided npc except the server
its just a dummy in game u can punch and stuff

im kinda just stuck on how i would do this

1 Like

spawn the dummy on the client, handle it on the client. easy and simple

however this could be easily exploitable as the client has full power over the dummy (it’s client-sided)

1 Like

yea but i need new players to also see it where its suppose to be seen like if a players throws the npc from point a to point b all the players ingame and new players that join should see the npc at point b

1 Like

Might require alot of :FireAllClients() via. a RemoteEvent. I haven’t tried it yet.

Spawn the dummy on the server and make everything that happens to the dummy happen over the server or use fire all clients events when anything happens to the dummy, which might actually just make more lag than just handling the dummy on the server

1 Like

I tried this with the ECS structure instead of OOP to render them on client as it works best personally, first thing i had in mind was how I should spawn and despawned some of my NPCs or render all of the alive NPCs to players who joined after the first client started but doing these are an extra work unlike putting them on the server side which is faster than setting it up on the client

onto first part here i want my NPCs to be spawned and went ahead makin it, except the part where i could spawn it for the players who just joined recently, let’s say a player named larry52 was the first person to join the game and he spawned 20 NPCs, he killed 5 and it remains 15 but then another player joined and they didn’t see what larry52 did and thought there’s a ghosts

This is my first problem and to solve this was to include additional info when a client spawned NPCs, i have the server created the whole list of data into a table stored in somewhere safe then send it to all clients spawning it with some data i want, used to sent, then i connect the events that checks if a new player has connected before spawning them based on the server, What i store on the server mostly was the ID and NPC type or name it stored

now larry52 and all other players are able to see!!! but what about despawning and damaging???

despawning whenever destroying or cleaning up isnt that pain, in some scenario where NPCs have their purpose to do such as damaging players or players damaging them, i ended up replicating some parts to the server and share it to other clients, This is similar to replicatin projectiles on client and do damage on the server when one of the client sees their projectile hitting the NPCs, for this one when i hit the NPC on the client, after the projectile touched, i then sent the damage to the server and replicate it to other clients, despawning shouldn’t be a problem no more! once it dies i can despawn to perform a cleanup.

For positioning when a new player joined, i didn’t move them to where the first client sees cuz using remotes to update it’s pos causes more network usage to rise up drastically especially when there are more than 100+ instead, i move them to where it was spawned at the start since there’s no other ways

note that what i talked above here is meant to be for multiplayer but if your game is a singleplayer then it’s useless to implement what i did above

1 Like