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)
I'll just say that I don't know how you can do this with UserInputService
, but mouse.Move
already seems to work fine.
I tested out your script. Everything works well except for the movement of the targetPart. I don't know if that's why you wanted to use something other than mouse.Move
. I used TweenService
in your onMouseMove function (on line 43), and the movement was fixed.
When I let go of the part which is where InputEnded
runs, the targetPart went back to its original position. That was fixed on line 53.
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 tweenService = game:GetService("TweenService") local player = game:GetService("Players").LocalPlayer local function onMouseMove() if not targetPart.Locked then targetPart.CanCollide = false targetPart.Anchored = true local tween = tweenService:Create(targetPart, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = CFrame.new(mouse.Hit.p)}) tween:Play() 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 targetPart.Position = mouse.Hit.p mouseMove:Disconnect() selectionBox:Destroy() if not wasAnchored then targetPart.Anchored = false end if wasCanCollide then targetPart.CanCollide = true end end end)
I think this might be what you mean, if it is you can edit it to your liking
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() Gui = Player.PlayerGui.GunShop InfoGui = Gui.InfoHover12 Module = require(game.ReplicatedFirst.GunInfo) Entered = false script.Parent.MouseEnter:connect(function() Entered = true InfoGui.Visible = true local info = Module.getInfo(script.Parent.Parent.Name) end) script.Parent.MouseLeave:connect(function() Entered = false InfoGui.Visible = false end) Mouse.Move:connect(function() if Entered then InfoGui.Position = UDim2.new(0,Mouse.X+10,0,Mouse.Y+20) end end)