Mouse.hit on the server not working

So i want to script mouse ai, that means if the players mouse is on a npc it will chase them but it doesnt work._.

while true do 
	for i, Player in pairs(game.Players:GetPlayers()) do
		local Mouse = Player:GetMouse()
		local Position = Mouse.Hit.p

09:16:47.764 Workspace.Dummy.AI:5: attempt to index nil with ‘Hit’ - Server - AI:5

1 Like

GetMouse only works on the client
I’d recommend you make that check on the client and send the result to the server once the mouse is on the NPC

Getting the mouse on the server returns nil, it only works on the client, you need to change your system to work with that