Getting the name of a gui using mouse

Hello, I want to get the name of a gui when the mouse hovers over it. Im not sure how to do this because mouse.Target doesn’t work with guis.
here is a grid layout and each frame is numbered, when the mouse goes over it I want it to print the name but im not sure how to do that.
image

You can make a loop that goes through each GuiObject and you use MouseEnter to check if the player is hovering over a GuiObject in this case

local folder = --Location of your folder that contains the objects you want them to print the name of

for _,v in pairs(folder:GetChildren()) do
	v.MouseEnter:Connect(function()
		print(v.Name)
	end)
end
1 Like

In a gui there is a statement of MouseEnter so you can add a local script in the GUI and write some code where it has mouseEnter

if you want a complex one with module here :slight_smile:

is there a way to make the v.Name get printed once until the player moves to the next item? because when I move over multiple items it starts to lag and prints the same thing 500 times

What do you mean by that? When you hover something, it gets printed multiple times even if you don’t change object? Or when you’re moving to other objects it prints it multiple times?

image
when I hover over 1 item it continuously prints the value, if i go to another slot then it will print that slot multiple times

That’s odd, it should only it print it when you enter it for the first time, Did you use MouseMove by any chance instead of MouseEnter?

image

What exactly is in the frame if I may ask

Its the base which has the slots as children. I did have "Slot"..v before
image

Try adding a condition before the statement since it could be that UiGridLayout

for _,v in pairs(frame:GetChildren()) do
    if not v:IsA("Frame") then return end
	v.MouseEnter:Connect(function()
		print(v.Name)
	end)
end

Also wait, how was it printing Slot12 when there’s only numbers? Was t hat a former name or did you write the content in the frame variable incorrectly?

thanks, this fixed it, it is slower but I can manage with that. I had "Slot"..v before and I removed that because i thought it might be something else.

1 Like

Alright, I’m glad that somewhat fixed it for you! If you have anymore issues don’t be afraid to make another post! Oh and if you’ll add anything else besides frames that you want the palyer to do something when they hover over it, just change up the

if not v:IsA("Frame") then return end

Line

1 Like