Question about mouse tracking for interactions

Hi

I’m making an interaction system for my game and I want it to be able to select multiple items within a range depending on where the mouse is pointing (I already have the rest of the system set up except from the multiple selection tracking)
How would I achieve this?
References:
https://gyazo.com/132cc0045b5e9caf53bdebf2eff934ed
https://gyazo.com/c110aae7d36364aaa7d0c3409de381e9 https://gyazo.com/77733f208d977e78579896e8e2d7fa37
https://gyazo.com/ee75cf52273d47e643f15a2134a041a0
https://gyazo.com/f5b8a08229e282f94854e50ad68d8d12

1 Like

You can simply use Mouse.Target and Mouse.Hit in this instance.
Reference: PlayerMouse | Documentation - Roblox Creator Hub
Mouse.Target will grab the Part that the mouse is hovering over.
Mouse.Hit will position where the mouse is hovering, and not the position of the targeted part.

local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
Mouse.Move:Connect(function()
	local Object = Mouse.Target
	local WorldPosition = Mouse.Hit
	if Object then
		print("The mouse is hovering over 'game."..Object:GetFullName().."' at Coordinates ("..tostring(WorldPosition.Position)..")")
	else
		print("The mouse is hovering over 'nothing' at Coordinates ("..tostring(WorldPosition.Position)..")")
	end
end)
1 Like

Ye I thought thats how you do it. But when I tried it, it didnt work but now I know why
Thank you

1 Like