script.Parent.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
held = true
local UserInputService = game:GetService("UserInputService")
local lastMousePosition = UserInputService:GetMouseLocation()
local mapPosition = script.Parent.Position
local mapPositionAsVector2 = Vector2.new(mapPosition .X.Offset, mapPosition .Y.Offset)
-- not using while loops.
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
print("yep")
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
print("yep2")
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
print("yep3")
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - mapPositionAsVector2
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
end
end)
No. Move the UserInputService.InputBegan function outside, and replace InputBegan to InputChanged (of the UIS one).
-- keep this function outside the script.Parent.InputChanged function. this is meant
-- to replace that function.
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
print("yep")
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
print("yep2")
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
print("yep3")
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - mapPositionAsVector2
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
Right, got it, it hit me right after I sent that that it’s probably not what you meant lol but it’s having the same problem where it can’t get past the first check, it won’t print “yep2”, I tried removing that check it also can’t seem to see that the input is mouse1button because “yep3” doesn’t print either.
script.Parent.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
held = false
end
end)
local UserInputService = game:GetService("UserInputService")
local lastMousePosition = UserInputService:GetMouseLocation()
local mapPosition = script.Parent.Position
local mapPositionAsVector2 = Vector2.new(mapPosition .X.Offset, mapPosition .Y.Offset)
-- keep this function outside the script.Parent.InputChanged function. this is meant
-- to replace that function.
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
print("yep")
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
print("yep2")
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
print("yep3")
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - mapPositionAsVector2
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
and the full script;
script.Parent.MouseWheelForward:Connect(function()
script.Parent.Size = script.Parent.Size + UDim2.new(0,50,0,50)
end)
script.Parent.MouseWheelBackward:Connect(function()
script.Parent.Size = script.Parent.Size - UDim2.new(0,50,0,50)
end)
local held = false
local mouse = game.Players.LocalPlayer:GetMouse()
--local function movemap()
-- while true do
-- wait(.01)
-- if held == true then
-- script.Parent.Position = UDim2.new(0,mouse.X,0,mouse.Y) - UDim2.new(0,script.Parent.Parent.AbsolutePosition.X,0,script.Parent.Parent.AbsolutePosition.Y) + UDim2.new(0,mouse.X,0,mouse.Y) - UDim2.new(0,script.Parent.AbsolutePosition.X,0,script.Parent.AbsolutePosition.Y)
-- print("updated")
-- end
-- end
--end
--script.Parent.InputChanged:Connect(function(input)
-- if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- held = true
-- movemap()
-- end
--end)
--script.Parent.InputEnded:Connect(function(input)
-- if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- held = false
-- end
--end)
local UserInputService = game:GetService("UserInputService")
local lastMousePosition = UserInputService:GetMouseLocation()
local mapPosition = script.Parent.Position
local mapPositionAsVector2 = Vector2.new(mapPosition .X.Offset, mapPosition .Y.Offset)
-- keep this function outside the script.Parent.InputChanged function. this is meant
-- to replace that function.
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
print("yep")
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
print("yep2")
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
print("yep3")
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - mapPositionAsVector2
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
You’ll have to include your frame’s InputBegan to make sure you only start dragging on the frame, and nowhere else. Then deactivate with UserInputService.InputEnded instead of the frame’s InputEnded to stop dragging the map after releasing your mouse in any part of the screen.
I also fixed an issue in my code where I mistyped something when calculating the delta.
-- this is the bottom half of your code
local UserInputService = game:GetService("UserInputService")
local lastMousePosition = Vector2.zero
local mapPositionAsVector2 = Vector2.zero
script.Parent.InputBegan:Connect(function(input)
if (input.UserInputType ~= Enum.UserInputType.MouseButton1) then return end
-- we store the current mouse and frame positions in this function.
local mapPosition = script.Parent.Position
mapPositionAsVector2 = Vector2.new(mapPosition .X.Offset, mapPosition .Y.Offset)
lastMousePosition = UserInputService:GetMouseLocation()
held = true
end)
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - lastMousePosition
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
UserInputService.InputEnded:Connect(function(inputObject, gameProcessed)
if (gameProcessed) then return end
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then return end
held = false
end)
Copy and pasted with some print checks and it is passing the second check however it isn’t passing the mouse1down check.;
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
print("yep")
if (gameProcessed or not held) then return end -- if the input is processed by the Roblox UI, or if the button is not held.
print("yep2")
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
print("yep3")
-- either GetMouseLocation or inputObject.Position
It only prints up to yep2, I tried to do an == and put the end at the end but that didn’t work either. Printing the userinputtype from the inputobj says that it doesn’t register mousebutton1 downs at all, only mouse movement and doesn’t even register that when hovering over the GUI.
In the InputChanged function, try removing the entire if (gameProcessed) line. I just realised now that it will stop the function because gameProcessed returns true when over a GUI element.
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
if (held) then return end
if (inputObject.UserInputType ~= Enum.UserInputType.MouseMovement) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - lastMousePosition
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
Awesome! It’s completely working now, just need a way to stop dragging, this bottom part should be the part that stops the dragging right? If so, it’s not
UserInputService.InputEnded:Connect(function(inputObject, gameProcessed)
if (gameProcessed) then return end
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then return end
held = false
end)
Full finished script for those looking for the solution;
script.Parent.MouseWheelForward:Connect(function()
script.Parent.Size = script.Parent.Size + UDim2.new(0,50,0,50)
end)
script.Parent.MouseWheelBackward:Connect(function()
script.Parent.Size = script.Parent.Size - UDim2.new(0,50,0,50)
end)
local held = false
local UserInputService = game:GetService("UserInputService")
local lastMousePosition = Vector2.zero
local mapPositionAsVector2 = Vector2.zero
script.Parent.InputBegan:Connect(function(input)
if (input.UserInputType ~= Enum.UserInputType.MouseButton1) then return end
-- we store the current mouse and frame positions in this function.
local mapPosition = script.Parent.Position
mapPositionAsVector2 = Vector2.new(mapPosition .X.Offset, mapPosition .Y.Offset)
lastMousePosition = UserInputService:GetMouseLocation()
held = true
end)
UserInputService.InputChanged:Connect(function(inputObject, gameProcessed)
if (not held) then return end
if (inputObject.UserInputType ~= Enum.UserInputType.MouseMovement) then
return -- we only want UserInputType.MouseButton1. anything else is discarded.
end
-- either GetMouseLocation or inputObject.Position
local mapOffsetDelta = UserInputService:GetMouseLocation() - lastMousePosition
local newMapPosition = mapPositionAsVector2 + mapOffsetDelta
script.Parent.Position = UDim2.new(0, newMapPosition.X, 0,newMapPosition.Y)
end)
UserInputService.InputEnded:Connect(function(inputObject, gameProcessed)
if (inputObject.UserInputType ~= Enum.UserInputType.MouseButton1) then return end
held = false
end)