whats up fellow dev people
im currently creating an operating system-ish thingy in roblox
Basically, the issue I’m having right now is i want this GUI (the window in the middle of the screen) to be drag-able (by player mouse cursor) in only the shaded red areas. I’ve implemented being able to move the window, but cant figure out how to make it only movable when the cursor is within the proper bounds.
local UIS = game:GetService('UserInputService')
local frame = script.Parent
local part = game:GetService("Workspace")["TVDark (reupload later, many bugs)"]:FindFirstChild("Resolution", true)
local cornerTL = part:WaitForChild('CornerTL') -- these are just the four corners of the screen
local cornerTR = part:WaitForChild('CornerTR')
local cornerBL = part:WaitForChild('CornerBL')
local cornerBR = part:WaitForChild('CornerBR')
local toggle = false
frame.InputBegan:Connect(function(input)
if script.Parent.Visible == true then
dragStart = UIS:GetMouseLocation()
startPos = frame.Position
toggle = true
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
toggle = false
end
end)
end
end
end)
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
if toggle == true then
local blx = game:GetService('Workspace').CurrentCamera:WorldToScreenPoint(cornerBL.WorldPosition).X
local brx = game:GetService('Workspace').CurrentCamera:WorldToScreenPoint(cornerBR.WorldPosition).X
local screen_resolution = game:GetService('Workspace').CurrentCamera.ViewportSize
local scaling_translation = 0.5 * screen_resolution.X / math.abs(blx - brx)
local delta = scaling_translation * (UIS:GetMouseLocation() - dragStart)
local udim2offx = math.clamp(
startPos.X.Offset + delta.X,
0 - (frame.Parent.Size.X.Offset - frame.Size.X.Offset)/(frame.Parent.Size.X.Offset/frame.Size.X.Offset),
(frame.Parent.Size.X.Offset - frame.Size.X.Offset)/(frame.Parent.Size.X.Offset/frame.Size.X.Offset)
)
local udim2offy = math.clamp(
startPos.Y.Offset + delta.Y,
0 - (frame.Parent.Size.Y.Offset - frame.Size.Y.Offset)/(frame.Parent.Size.Y.Offset/frame.Size.Y.Offset),
(frame.Parent.Size.Y.Offset - frame.Size.Y.Offset)/(frame.Parent.Size.Y.Offset/frame.Size.Y.Offset)
)
--print('=====')
--print('startPos.[X,Y].Scale = ['..startPos.X.Scale..','..startPos.Y.Scale..']')
--print('delta.[X,Y] = ['..delta.X..','..delta.Y..']')
--print('UIS:GetMouseLocation()[X,Y] = ['..UIS:GetMouseLocation().X..','..UIS:GetMouseLocation().Y..']; dragStart.[X,Y] = ['..dragStart.X..','..dragStart.Y..']')
--print('udim2off[x,y] = ['..udim2offx..','..udim2offy..']')
frame.Position = UDim2.new(
startPos.X.Scale,
udim2offx,
startPos.Y.Scale,
udim2offy
)
end
end
end)
and then the playerGUI looks like this
ive tried many things but alas none of them have worked
my brain is total mush right now and any help is greatly appreciated!!!