Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does the gui go all weird when clicked on?

Asked by 4 years ago

i have a gui in a game of mine that i want to transfer to another game so im using a plugin to make the gui into a script but when i click minimize it goes to a completely different corner, and when i click size uip it doesnt go anywhere, just sizes up. please help here is the local script

-- applebee
-- Version: 3.0
-- Instances:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ScreenGui = Instance.new("ScreenGui")
local Frame = Instance.new("Frame")
local Autofarm = Instance.new("TextButton")
local Minimize = Instance.new("TextButton")
--Properties:
ScreenGui.Parent = player:WaitForChild("PlayerGui")
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.new(1, 1, 1)
Frame.Position = UDim2.new(0.344735265, 0, 0.215235725, 0)
Frame.Size = UDim2.new(0, 586, 0, 323)

Autofarm.Name = "Autofarm"
Autofarm.Parent = Frame
Autofarm.BackgroundColor3 = Color3.new(0.129412, 1, 0.129412)
Autofarm.Size = UDim2.new(0, 200, 0, 50)
Autofarm.Font = Enum.Font.SourceSans
Autofarm.Text = "Autofarm"
Autofarm.TextColor3 = Color3.new(0, 0, 0)
Autofarm.TextSize = 14

Minimize.Name = "Minimize"
Minimize.Parent = Frame
Minimize.BackgroundColor3 = Color3.new(0.337255, 1, 0.0313726)
Minimize.Position = UDim2.new(0, 535, 0, 0)
Minimize.Size = UDim2.new(0, 49, 0, 17)
Minimize.Font = Enum.Font.SourceSans
Minimize.Text = "minimize"
Minimize.TextColor3 = Color3.new(0, 0, 0)
Minimize.TextSize = 14
-- Scripts:

Minimize.MouseButton1Click:Connect(function()
    if Minimize.Text == "minimize" then
        Minimize.Text = "Size up"
        Minimize.Size = UDim2.new(0, 49, 0, 17)
        Frame.Position = UDim2.new({0.719, 0},{0.082, 0})
        Autofarm.Visible = false
        Minimize.Position = UDim2.new(0, 535, 0, 0)
    else
        Minimize.BackgroundColor3 = Color3.new(0.337255, 1, 0.0313726)
        Minimize.Size = UDim2.new(0, 72, 0, 25)
        Minimize.Font = Enum.Font.SourceSans
        Minimize.Text = "Minimize"
        Minimize.TextColor3 = Color3.new(0, 0, 0)
        Minimize.TextSize = 14
        Autofarm.Visible = true
    end
end)


i have another script in here as well but there is no need to bring that in

here is how it looks like https://imgur.com/a/7NIoONm

for those wondering why there is an autofarm in there thats because im working on a gamepass that allows autofarming

1 answer

Log in to vote
1
Answered by
gskw 1046 Moderation Voter
4 years ago

There are two minor bugs in different places that cause the behaviour you're seeing. Firstly, we'll see why the Frame jumps to a different corner when being minimized. The issue can be found in the following line:

Frame.Position = UDim2.new({0.719, 0},{0.082, 0})

In my personal opinion, Roblox should throw an error as it would make the mistake easier to catch. The code tries to pass two tables to UDim2.new(), which expects either four integers to two UDim values. This results in a "zero" UDim2 being created. You could change the code to either one of the following lines to fix the issue:

Frame.Position = UDim2.new(0.719, 0,0.082, 0)
Frame.Position = UDim2.new(UDim.new(0.719, 0), UDim.new(0.082, 0))

Now, why does the GUI not move when you size it up? This is simply because the sizing up code never sets the Frame's position. You probably want to place the following line in that block:

Frame.Position = UDim2.new(0.344735265, 0, 0.215235725, 0)

Also, be aware that sizing up sets the text to "Minimize", while the if condition checks if it's "minimize", in lowercase. More idiomatically, you could use a boolean variable to track whether the GUi is minimized, or disconnect and connect the event to a different function every time it's toggled.

0
um spotted my tiny mistake Gameplayer365247v2 1055 — 4y
Ad

Answer this question