Mouse.Move:Connect(function()
if scalingPressed == true then
if #guisatposition ~= 0 then
local start = guisatposition[1].Position- (UDim2.new(Mouse.X,0, Mouse.Y,0))
local p = start.X.Scale
local d = start.Y.Scale
local a = guisatposition[1].Size.X.Scale
local b = guisatposition[1].Size.Y.Scale
guisatposition[1].Size = UDim2.new((a + p)/6000, 0, (b + d)/6000, 0)
end
end
end)
Hello! I am trying to make it so you can scale a gui with your mouse (guisatposition is a gui)
So, the guisatposition[1] is a GUI object, so I am trying to make it so when the mouse moves, if it moves outward then the guisatposition[1] will get bigger, if it moves closer to the gui then it will get smaller, so I am doing with the start variable finding distance between them, and then at the end when i size the guisatposition, i added up the OG scale of the gui with the start variable scale on both the X and y, divide by 6000 so it isnt such a big number. It works, but it works the wrong way as in when you move your mouse out it gets smaller, when you move it in in gets bigger, i want it the other way around, any idea what I am doing wrong?
This keeps happening whenever I try to do this.
I attempted to make it negative/positive, it did not work, any ideas?
Hmm, maybe try guisatposition[1].Size = UDim2.new((a + p)*6000, 0, (b + d)*6000, 0)
Either that or switch 6000 out for -6000
I’m equally confused as you are.
You should probably make “start” an absolute value of the difference between gui position and the mouse position so it’s never negative
Here’s a quick example I made for you
local Mouse = game:GetService'Players'.LocalPlayer:GetMouse()
local Frame = script.Parent
local ScreenGui = Frame.Parent
local Scaling = false
local OriginalSize
local ClickedRadius
-- Gets magnitude between mouse position and center of passed frame
local function MagnitudeOfMouseFromFrameCenter(Frame)
local MousePosition = Vector2.new(Mouse.X, Mouse.Y)
local FrameCenter = Vector2.new(Frame.AbsolutePosition.X + Frame.AbsoluteSize.X / 2, Frame.AbsolutePosition.Y + Frame.AbsoluteSize.Y / 2)
local Magnitude = (MousePosition - FrameCenter).Magnitude
return Magnitude
end
Mouse.Move:Connect(function()
if not Scaling then return end
-- if current mouse magnitude from frame center is higher than when clicked
-- then the "Magnitude" variable would be positive
-- (mouse is farther from center of frame than when first clicked)
-- and vice versa
local Magnitude = MagnitudeOfMouseFromFrameCenter(Frame) - ClickedRadius
-- Resize frame relative to its original size
-- when it was first clicked
Frame.Size = OriginalSize + UDim2.new(Magnitude / 6000, 0, Magnitude / 6000, 0)
end)
Frame.InputBegan:Connect(function(Input)
if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
-- Enable scaling with mouse
Scaling = true
-- Store original size of frame for later
OriginalSize = Frame.Size
ClickedRadius = MagnitudeOfMouseFromFrameCenter(Frame)
end)
Frame.InputEnded:Connect(function(Input)
if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
Scaling = false
OriginalSize = nil
ClickedRadius = nil
end)
So I actually was trying one last thing, I was trying to do scale * offset, so i turned the scale size of the gui into offset, did the calculations, and then i turned it back and it worked fine.