I have a server script that basically makes the npc always face the player by using align orientation and updating the orientation using heartbeat event. the problem is that this is extremely taxing on the server and gets really laggy when I spawn more than 5 npcs.
I have tried doing this on the client side but the npc is stuck at one orientation even if I dont set the networkowner to nil. basically I just had a client runservice that did a loop through an npc folder and set the orientation to the player
I have heard about using remote events to let the client handle the work but I’m unsure on how to approach it. And what should the networkowner be?
function BaseNPC:Orientation()
local AlignOrientation = self._Model.HumanoidRootPart.RootAttachment:FindFirstChild("AlignOrientation")
local player = PS:FindFirstChild(self._Model:GetAttribute("Target"))
if not player or not player.Character then return end
if not AlignOrientation then
AlignOrientation = self:AlignOrientationSetUp()
else
local PlayerPosition = player.Character.HumanoidRootPart.Position
local NPCPosition = self._Model.HumanoidRootPart.Position
local Difference = (NPCPosition - PlayerPosition)
local Angle = math.atan2(Difference.X, Difference.Z)
if not self._Model:GetAttribute("Stunned") then
AlignOrientation.CFrame = CFrame.Angles(0, Angle, 0)
else
AlignOrientation.CFrame = CFrame.Angles(0,0,0)
end
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.