Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

What purpose do you want to use f1 and f2 for? What kind of code would use them?

0

I want to destroy the frames when the Mouse Leaves the button.

1 answer

✓ Accepted answer

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).

This discussion is preserved as it was. New answers, comments, and votes are closed.