I am trying to make a script that a part will float to the position of where the mouse is being held down. However, I can't find anyway to get the position of the mouse while it's being held down, only where it clicks. Is it even possible to get the position of where the mouse is while it is held down?
This is what I've tried and it only shows where the mouse clicks:
--// Services
local UserInputService = game:GetService("UserInputService")
--// Objects
local Held = false
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
Held = true
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local MouseCFrame = Mouse.Hit
local MousePosition = MouseCFrame.p
print (MousePosition)
end
end)
UserInputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
Held = false
end
end)

1 comment
get rid of "Held" and change the if to a while