Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with mouse.hit rising?

Hello, When i try to use mouse.hit it keeps going towards the camera. How would i fix this?

script.Parent.Activated:connect(function()
	local mouse = game.Players.LocalPlayer:GetMouse()
	mouse.keyDown:connect(function(key)
		if key == "i" then
			local Highlight = Instance.new("Part",workspace)
				Highlight.Anchored = true	Highlight.CanCollide = false
				Highlight.Size = Vector3.new(2.5,.1,2.5)
			while wait() do
				if mouse.hit.p then
					local Ignore = {script.Parent,game.Players.LocalPlayer.Character}
					local Ray = Ray.new(script.Parent.Handle.CFrame.p,(mouse.Hit.p - script.Parent.Handle.CFrame.p).Unit*50)
						local Part,Position = workspace:FindPartOnRayWithIgnoreList(Ray,Ignore,false,true)
					Highlight.CFrame = CFrame.new(Position.X,Position.Y,Position.Z)
				end
			end
		end
	end)
end)

1 answer

✓ Accepted answer

It's because the ray is hitting Highlight. Add Highlight to the ignore list.

local Ignore = {script.Parent,game.Players.LocalPlayer.Character, Highlight}

1 comment

0

I can't belive i missed that.

This discussion is preserved as it was. New answers, comments, and votes are closed.