Help With Mouse.Target

So I want to be able to get an enemy’s root part through Mouse.Target, however, I get an error and I can’t figure it out. The output says " Attempted to index nil with “Target”

local aircombat = ReplicatedStorage.AirCombat:WaitForChild("Mouse")

aircombat.OnServerEvent:Connect(function(Player)
	local mouse = Player:GetMouse()
	if mouse.Target then  -- THE LINE OF ERROR
		if mouse.Target.Parent:IsA("Model") then
			local HumanoidRootPart = mouse.Target.Parent:FindFirstChild("HumanoidRootPart")
			if HumanoidRootPart then
				print("RootPart found")
			else 
				print("Not Found")
			end
		end
	end
end)

mouse might be nil. Check if mouse ~= nil before trying mouse.Target.

Seeing that this code is a server script, the server doesn’t have a mouse. :GetMouse() only worked on the client.

only local scripts can have access to the mouse of the player

Hm is there any other way to get an enemy’s root part when their mouse is near them?

Run this code on the client in a local script and have them tell the server with a remote event.

you could make the script into a local script and fire a RemoteEvent so a server-scripts does the work