An interest I’ve had is how could I make server-sided “NPC”, but a client rendered NPC.
Namely, the server side would just be a part that floats and pathfinds around an environment, while the client would render, say, a zombie and each part would become invisible, while keeping a zombie NPC to where the serversided part would be.
Now my biggest question is, how is this achievable, is there somewhere I can read or watch about this? I’ve been somewhat lost on how to achieve this!
I also want to know if this is a viable method or not, the pros and cons.
Theres this video that I’ve seen, https://youtu.be/JyMxrcqEzu8?si=N1Lk-a2gcRfg0FfQ, which is great and i learnt a lot, but my biggest question if that video in particular can make it so the npcs can deal or receive serversided damage, so thats why i want to attempt this “theory” of a server sided part that represents the NPC to the server, and a client rendered NPC for visuals.
If you deal damage to npc on client, it doesn’t matter if the npc is on server or client, they only take the damage on that client’s device. If you deal damage to the client, it doesn’t matter if it’s from server or client, since client own their character. If the character has died on their device, then it’s also died on the server.
Usually, you just weld a npc created on client to a server side invisible part, you control the part to move, and have your custom health logic on the server side along with the invisible part, then you deal damage to the part on the server.
You don’t even need a brick, the easiest way to do this is to use something like ReplicaService to manage your new NPCs and replicate their data to the client.
All you have to do then is update the position on the server, and have the client render and do the pathfinding.
Then you can do cool stuff like culling NPCs that are not visible, and slowing down the update rate of NPCs that are far away.
Suphi Kaner is amazing! If you would like to achieve something like the following:
Server:
Client:
I can help you. It depends on what systems you intend on using, but if the damage is server side you will need a physical rig. If not, you could just store info on the NPCs in a table. When you create the NPC on the server, tell the client the information and send along the NPC model through a remote event. On the client, destroy the original NPC, and clone the high quality model in it’s place. Whenever you make a change on the server(health, position, etc) tell the client. Avoid playing animations on the server. Really depends on whether your damaging system is client or server. If it is client(like most modern gun systems), you will need to handle that specifically and modify your engine to use the data, and not the physical rig. You only need a physical rig for server sided hit detection. Generate a random ID or have a seqential number assigned to NPCs(make sure it only goes up, don’t want any duplicates).
I don’t think client-side rendering will be much better than on the server. On the contrary, since the model is rendered on the client, it will be located in ReplicatedStorage, which will increase the initial memory usage.
Why would I not need the brick, wouldnt I still need to have some server element, especially for something like zombies where they would need to receive damage & dish out damage as well?
Or is that something that can be handled some other way?
I think you are confusing some different usages up. If the model is ever seen by the client, it will need to be downloaded by them. Playing animations on the server is a waste, and they will be somewhat laggy/delayed when seen by clients. I don’t know what you are trying to say, but optimization is the goal here.
How are players damaging the zombie? I’m PvP it can be quite important to do the hit detection for bullets from the server. This is because security is essential if you don’t want hackers killing other players. For PvE, it’s less of an issue. You can stop someone from shooting too fast and double check their damage and ammo. On the client, complete all hit detection. Use a remote event to the server to tell everyone to render the bullet. The client that is shooting should render the bullet instantly, and ignore any requests to create bullets that they didn’t initiate(use the server to add delays and check the ammo here, don’t want someone lagging everyone out). When you hit an NPC, give the server its ID(and maybe the name of the part you hit, for like double head damage and stuff). The server will store the information for all of the NPCs in a table. You can access that table using the ID. Here’s an example of what that table could store:
local NPCs = {}
local count = 0
local NPC_Event = game.ReplicatedStorage.NPC_Evenr
local function spawnNPC(position)
local ID = count
count += 1
local obj = {
Health = 100,
Position = position,
Target = nil,
}
NPCs[ID] = obj
NPC_Event:FireAllClients(obj)
end
I probably made some mistakes in the code/spelling mistakes as I just woke up, and I’m writing all of this from my phone. Best of luck!