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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
2
Answered by
VRGamez 27
7 years ago

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
0
Will it cause lag? i think no Lolamtic 63 — 7y
0
It wont cause lag, and if it does, and a wait(.1) to it VRGamez 27 — 7y
0
It would be better if you only connected the event to the frame not every child. User#5423 17 — 7y
0
Use :IsA('GuiObject') if you want it to be compatible with all gui objects. Also, use :GetDescendants() hiimgoodpack 2009 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
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 awfulszn 394 — 7y

Answer this question