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

How do I return a value from a robloxevent:Connect(function() ?

Asked by 4 years ago
for i,v in pairs(buttons:GetChildren()) do
    v.MouseEnter:Connect(function()
        local xscale = v.Position.X.Scale
        --1
        local f1=Instance.new("Frame")
        f1.Parent = gui
        f1.BorderSizePixel = 0
        f1.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
        f1.Size = UDim2.new(0.014,0,0,0)
        f1.Position = UDim2.new(xscale + 0.293, 0, v.Position.Y.Scale, 0)
        print(f1.Position)
        --2
        local f2=Instance.new("Frame")
        f2.Parent = gui
        f2.BorderSizePixel = 0
        f2.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
        f2.Size = UDim2.new(0.014,0,0,0)
        f2.Position = UDim2.new(xscale + 0.293, 0, v.Position.Y.Scale + 0.119, 0)
        --tween
        f1:TweenSize(UDim2.new(0.014, 0, 0.06, 0), "In","Linear",0.2,true)
        f2:TweenSize(UDim2.new(0.014, 0, -0.06, 0), "In","Linear",0.2,true)

        return f1,f2
    end)

How would I acquire f1 and f2 from this piece of code so I can use it outside the function? Thanks.

0
What purpose do you want to use f1 and f2 for? What kind of code would use them? gskw 1046 — 4y
0
I want to destroy the frames when the Mouse Leaves the button. Shrilleh 68 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Increase the scope of your f variables. If you define them as local before the v.MouseEnter line (between lines 1 and 2), you can have a v.MouseLeave after line 24 that uses them also.

If you want all buttons to share these frames, you can instead define f1/f2 on line 1 (and have extra logic for when the user is moving the mouse between frames).

Ad

Answer this question