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)
Your script is good, but to make the part constantly follow the player use this method:
--// Services local UserInputService = game:GetService("UserInputService") --// Objects local Held = false UserInputService.InputBegan:Connect(function(inputObject) while inputObject.UserInputType == Enum.UserInputType.MouseButton1 then -- sets the position on a constant loop until conditions are no longer met. print("firm clasp") --debugging statement Held = true local plr = game.Players.LocalPlayer local Mouse = plr:GetMouse() local MouseCFrame = Mouse.Hit local MousePosition = MouseCFrame.p print (MousePosition) wait() --prevents script for crashing end end) UserInputService.InputEnded:Connect(function(inputObject) if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then print("ungrip") --debugging statement Held = false end end)