Raycast script giving error

My ray cast script is not working and it’s giving me this error:

 Players.CloutBl0x.Backpack.Revolver.GunHandler:82: attempt to index nil with 'Hit'  -  Server - GunHandler:82

(line 82 is the ray variable/the first line below)

Raycast Script:

		local ray = Ray.new(handle.Position, (mouse.Hit.p - muzzle.Position).Unit * maxRange.Value)
		local hit, pos = workspace:FindPartOnRay(ray, character)
		
		if hit ~= nil then
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid:TakeDamage(math.random(damageMinMax.Value))
			end
		end
		

Try using mouse.Hit.Position instead of mouse.Hit.p

show how you’re initiating the mouse variable

you can only get mouse from localscript

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.