How do I load and unload NPCs like My Restaurant did, I need some optimization to support a lot of player

I need to load and unload only NPCs, they are really expensive to run all the time, I need to know how to remove it on client-side so it will be less expensive

2 Likes

What do you mean by “expensive”? Do you mean memory-consuming?
I honestly have no idea to do this, just wondering what you meant. Hope you get help from a professional!

1 Like

yes

30 charsssssss…

bump, still need help thanks reee

bump, still need help thanks again

Well , I don’t think it is complicated. I might have an idea.

In your local script , fire a server event (assume you have created a remote event) like so;-

local Event = game.ReplicatedStorage.MyEvent
Event:FireServer()

In a server script , create a connection function for that event;-

game.ReplicatedStorage.MyEvent.OnServerEvent:connect(function(Player)
      game.ReplicatedStorage.MyEvent:FireAllClients(s)
end)

So basically , you are telling the server to tell all the client to do the same thing (this will save memory for server because server doesn’t need to render the humanoid/npc)

Finally , in the previous local script . Create a connection function for that event .

game.ReplicatedStorage.MyEvent.OnClientEvent:connect(function()
      local NPC = game.ReplicatedFirst.MyNPC:Clone()
      NPC.Parent = workspace
      ----------// do like CFrame position and all that stuff for the NPC.
end)

This way , The server doesn’t render anything at all. Only you and all the other player can see it.
There is a downside though , player that have ‘hacking capabilities’ can fire that event at will . So I might suggest you put some security on that.

By the way , I did not test the code I write above. There might be typos.

1 Like

What they most likely do is detect whenever the clients enter a restaurant and then render them locally, and when they player is not in that restaurant they parent the npcs to ReplicatedStorage. All the npc animations are most likely done from the client, and maybe they do the moving on the server, but they might do everything on the client.

1 Like