How to locate the mouse or the position of it

  1. What do you want to achieve?
    How to draw where to mouse is at?
  2. What is the issue?
    I have no idea how to do that.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Nothing really.
script.Parent.MouseHoverEnter:Connect(function()
	local part = Instance.new("Part")
	part.Name = "Drawing"
	part.Parent = workspace.Draw
	part.Position = script.Parent
end)

script.Parent.MouseHoverLeave:Connect(function()
	workspace.Draw:Destroy()
	wait()
	local folder = Instance.new("Folder")
	folder.Name = "Draw"
	folder.Parent = workspace
end)

The code above is what I’m gonna do when someone goes near the board and draws.

Use the UserInputService

local UserInputService 	= game:GetService("UserInputService")
--
-- Handle mouse button
--
local function onInputBegan(input, gameProcessed)
	if gameProcessed then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		UserInputService:GetMouseLocation() 	-- this is the screen position (x, y)
	end
end

--
-- Handle touch screen
--
local function onTouchEnded(touch, processedByUI)
	if processedByUI then return end
	touch.Position -- this is the screen position (x, y)
end

UserInputService.TouchEnded:Connect(onTouchEnded)
UserInputService.InputBegan:Connect(onInputBegan)

Okay! Thank you very much! It was very helpful.

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