How can i make a button that resizes a Frame when i press it and stops resizing when i let go.
Kinda like in the Dev Console.
You should make a boolean variable that displays if the button is pressed.
Get the difference between the x coordinate of the top-left corner of your frame and the mouse x position, and then you do the same thing for the y positions. Then you set the size of the frame. This should be done in a while true loops that runs when the booleans that displays if the button is pressed is true.
I hope this gives an idea of how you could do this.
How can i get the difference between the two points?
Simple math.
PointA - PointB
PointB is the smallest value.
By “PointA - PointB” you mean PointA minus PointB
you can also show me a script example
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local function GetDifference(A, B)
return A-B --Here we're doing what i explained in the reply.
end
--This should be in a loop. I suggest RunService:RenderStepped().
local PointA = Vector2.new(250, 152) --This is the position of the frame's top-left corner. You could get this position by using frame.AbsolutePosition
local PointB = Vector2.new(mouse.X, mouse.Y) --This is the position of the mouse.
local S = GetDifference(PointA, PointB) --This is how big you should make your frame.
--Then you would do: frame.Size = UDim2.new(0, S.X, 0, S.Y)
Here you go! I hope this gives you a basic understanding about how you should do your math.
it worked but it is the other way around. So when i move my mouse to the right the frame goes left.
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local pressed = false
local function GetDifference(A, B)
local S = Vector2.new(math.clamp(B.X - A.X, 0, math.huge), math.clamp(B.Y - A.Y, 0, math.huge))
return S
end
game:GetService("RunService").RenderStepped:connect(function()
if pressed == true then
local PointA = script.Parent.AbsolutePosition
local PointB = Vector2.new(mouse.X, mouse.Y) --This is the position of the mouse.
print(PointA.X ..",".. PointA.Y ..", "..PointB.X ..",".. PointB.Y)
local S = GetDifference(PointA, PointB) --This is how big you should make your frame.
--Then you would do: frame.Size = UDim2.new(0, S.X, 0, S.Y)
script.Parent.Size = UDim2.new(0, S.X, 0, S.Y)
end
end)
I think this is what you want. You just need to add event to change the pressed boolean variable.
it workes but at the same time not as i wnat you can see it in the pic
abd i have no idea how to fix this
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local pressed = false
local function GetDifference(A, B)
local S = Vector2.new(math.clamp(B.X - A.X, 0, math.huge), math.clamp(B.Y - A.Y, 0, math.huge))
return S
end
game:GetService("RunService").RenderStepped:connect(function()
if pressed == true then
local PointA = script.Parent.AbsolutePosition
local PointB = Vector2.new(mouse.X, mouse.Y) --This is the position of the mouse.
print(PointA.X ..",".. PointA.Y ..", "..PointB.X ..",".. PointB.Y)
local S = GetDifference(PointA, PointB) --This is how big you should make your frame.
--Then you would do: frame.Size = UDim2.new(0, S.X, 0, S.Y)
script.Parent.Size = UDim2.new(0, S.X, 0, S.Y)
end
end)
I think this is what you want. You just have to change the pressed boolean variable to with events from the button.
Yes, that worked thank you.
if you want to play the Game that i use that in, then heres the game link: [ Content Deleted ] - Roblox
I really enjoyed your game, 00011110 chars