I'm trying to change the brick color when it finds a part,but it won't change because I keep getting a error:

Workspace.Script:7: attempt to index local 'hit' (a nil value)

script:

while wait()do
    local Ray = Ray.new(game.Workspace.Part1.Position,
    game.Workspace.Part1.CFrame.lookVector.unit*10) -- 1000 is normally used, but you can reduce as you see fit. Not multiplying this is only 1 stud from Part1's *center* towards its lookVector.

    local hit,position = Workspace:FindPartOnRay(Ray,_)

    if hit:IsA("Part") then
	game.Workspace.Part1.BrickColor = BrickColor.new("Bright green")
else
	game.Workspace.Part1.BrickColor = BrickColor.new("Bright red")
end
end

Why and how would I fix this?