Is there anything like Mouse.Move for UserInputService? I know there's InputChanged but it doesn't seem to work for me. I'm trying to create a building tool and it would be better if it's all UserInputService. (Line 45.) This is what i've done so far:
local UserInputService = game:GetService("UserInputService")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
mouse.TargetFilter = script.Parent -- I wrote script.Parent because it's in StarterCharacterScripts
local wasAnchored
local wasCanCollide
local targetPart
local selectionBox
local mouseMove
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessedEvent then
targetPart = mouse.Target
selectionBox = Instance.new("SelectionBox")
selectionBox.Adornee = targetPart
selectionBox.Parent = targetPart
if targetPart.Anchored then
wasAnchored = true
else
wasAnchored = false
end
if targetPart.CanCollide then
wasCanCollide = true
else
wasCanCollide = false
end
local function onMouseMove()
if not targetPart.Locked then
targetPart.CanCollide = false
targetPart.Anchored = true
targetPart.Position = mouse.Hit.p
end
end
mouseMove = mouse.Move:Connect(onMouseMove)
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessedEvent then
mouseMove:Disconnect()
selectionBox:Destroy()
if not wasAnchored then
targetPart.Anchored = false
end
if wasCanCollide then
targetPart.CanCollide = true
end
end
end)

2 comments
No, I meant a tool that grabs parts and can place it somewhere.
oh yh that wont work