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

How can I make my GUI hover over failproof? [answered]

Asked by 4 years ago
Edited 4 years ago

I have a GUI where each time I hover over a button, it highlights it by creating a little bar beneath it, which gets removed when the mouse leaves, however if you spam wipe your mouse over all the buttons, the bar sometimes stays.

https://gyazo.com/895f9844329d794c111d04d5e0218566

The code which handles the creation and tweening,

local options = script.Parent.Options

for i,v in pairs(options:GetChildren()) do
    if v.Selectable == true and v:IsA("TextButton") then
        v.MouseEnter:Connect(function()
            print(v.Name)
            frame = Instance.new("Frame")
            frame.Visible = false
            frame.Parent = options
            frame.Size = UDim2.new(0, 0,0.015, 0)
            frame.BackgroundColor3  = Color3.fromRGB(255,255,255)
            frame.BorderSizePixel = 0
            frame.Position = UDim2.new(0.191,0,v.Position.Y.Scale + 0.13,0)
            frame.Visible = true
            frame:TweenSize(UDim2.new(0.645,0,0.015, 0),"Out","Linear",0.3)
        end)

        v.MouseLeave:Connect(function()
            frame:Destroy()
        end)
    end
end 

How can I add to my code to make sure that this doesn't occur? Thanks.

0
Ok I made the frame that was being created be named (v.Name.."-Frame") and each time I ran the MouseEnter event I'd check if (v.Name.."-Frame") already existed, and if it did, I made the script delete it. Please still feel free to answer or comment with alternative solutions. Shrilleh 68 — 4y
0
i guess i was too late Fad99 286 — 4y
0
I would use TweenService for any new work. It has parameters built it to prevent this, unlike :TweenSize / :TweenPosition / :TweenSizeAndPosition MessorAdmin 598 — 4y
0
https://developer.roblox.com/en-us/api-reference/function/TweenService/Create here the link for an example at TweenService MessorAdmin 598 — 4y

1 answer

Log in to vote
1
Answered by
Fad99 286 Moderation Voter
4 years ago
local options = script.Parent.Options

for i,v in pairs(options:GetChildren()) do
    if v.Selectable == true and v:IsA("TextButton") then
        v.MouseEnter:Connect(function()
        if options:FindFirstChild("Frame") Then options.Frame:Destroy() -- This Should Work
            print(v.Name)
            frame = Instance.new("Frame")
            frame.Visible = false
            frame.Parent = options
            frame.Size = UDim2.new(0, 0,0.015, 0)
            frame.BackgroundColor3  = Color3.fromRGB(255,255,255)
            frame.BorderSizePixel = 0
            frame.Position = UDim2.new(0.191,0,v.Position.Y.Scale + 0.13,0)
            frame.Visible = true
            frame:TweenSize(UDim2.new(0.645,0,0.015, 0),"Out","Linear",0.3)
        end)

        v.MouseLeave:Connect(function()
            frame:Destroy()
        end)
    end
end 

When you hover over a new button and there is still a frame it will delete it otherwise that line of code is ignored.

Ad

Answer this question