Im making a game where the npcs stare at you and I am trying to use CollectionService to make all the npcs look at the player but only one is facing the player. This is the script:
RunService = game:GetService("RunService")
CollectionService = game:GetService("CollectionService")
game.Players.PlayerAdded:Wait()
plr = game.Players:GetChildren()
for _, Player in plr do
plr = Player
break
end
for _, NPCs in CollectionService:GetTagged("NPC Stare") do
character = plr.Character or game.Players[plr.Name].CharacterAdded:Wait()
NPCSS = game.Workspace:GetChildren("NPCs")
print("HERE")
RunService.Heartbeat:Connect(function()
local npcPosition = game.Workspace.NPCs.NPC.PrimaryPart.Position
local targetPosition = plr.Character.Torso.Position
task.wait()
game.Workspace.NPCs.NPC.PrimaryPart.CFrame = CFrame.lookAt(npcPosition, targetPosition)
end)
end
