CollectionService is not using everyone properly?
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:
01 | RunService = game:GetService( "RunService" ) |
02 | CollectionService = game:GetService( "CollectionService" ) |
03 | game.Players.PlayerAdded:Wait() |
05 | plr = game.Players:GetChildren() |
07 | for _, Player in plr do |
14 | for _, NPCs in CollectionService:GetTagged( "NPC Stare" ) do |
17 | character = plr.Character or game.Players [ plr.Name ] .CharacterAdded:Wait() |
19 | NPCSS = game.Workspace:GetChildren( "NPCs" ) |
23 | RunService.Heartbeat:Connect( function () |
24 | local npcPosition = game.Workspace.NPCs.NPC.PrimaryPart.Position |
25 | local targetPosition = plr.Character.Torso.Position |
30 | game.Workspace.NPCs.NPC.PrimaryPart.CFrame = CFrame.lookAt(npcPosition, targetPosition) |