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

How to fire a function when one of multiple "specific Frames" gets mouseentered?

Im trying to make a LocalScript It fires a function if script.Parent:GetChildren() Are mouseentered but it wont work

local childs = script.Parent:GetChildren()
childs.MouseEnter:connect(function()
	print("works")
end)

Error: MouseEnter is a nil value

2 answers

✓ Accepted answer

This is a constant loop, whenever a mouse enter any of the frames, it will print "Worked"

local children = script.Parent:GetChildren() --Returns a table of all children in a given parent

for i,child in pairs(children) do -- Child is equal to every value in the children variable 
	child.MouseEnter:connect(function()
		if child.ClassName == "Frame" then --If child is a frame then it prints 'Worked'
			print("Worked")
		end
	end)
end

4 comments

0

Will it cause lag? i think no

0

It wont cause lag, and if it does, and a wait(.1) to it

0

It would be better if you only connected the event to the frame not every child.

0

Use :IsA('GuiObject') if you want it to be compatible with all gui objects. Also, use :GetDescendants()

You should do a for function if you want all the childs to be able

for child in pairs(script.Parent:GetChildren())
	childs.MouseEnter:connect(function()
		print("Works")
	end
end

1 comment

0

Please explain the code, what you did to fix it, what it does etc. This will ensure they understand it, and will aid to stop duplicate posts by other people with the same problem. Thanks

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