Help with MouseEnter

Hi! I am having trouble making a computer mouse maze (a game where you try to get your mouse through without touching the walls.) I have a blank TextButton as the walls and use the MouseEnter event in my script. Since i will have multiple walls in the game I need help to find all the TextButtons in a script. So far i have this:

for i, v in pairs (game.StarterGui:GetDescendants()) do
	while true do
		wait()
		v.Name.MouseEnter:Connect(function()
			if v.Name == "Border" then
				print("Worked")
			end
		end)
	end
end

I am a beginner at scripting so i might be missing something obvious.

Hello everyone.
Where is the While true do taking play? For me, I wouldn’t recommend using it here, and also because you need to trigger a mouse entering the gui.
Instead I’ll go for:

v.Name.MouseEnter:Connect(function()
   if v.Name == "Border" then
      print("Sus")
   end
end

Also make sure that this code is in a local script and referencing the gui that you’re trying to read.

I’m pretty sure he is only showing part of his code, he would need it to identify it at an interval

I do agree it should be set up differently though.

1 Like

Sorry, it doesn’t work and it comes back with a error:

Players.ZackDaQuackYT.PlayerGui.ScreenGui.Frame.Scripts.CoreScript:2: attempt to index nil with ‘Connect’ - Client - CoreScript:2

It is indexing “v.Name.MouseEnter” as a nil because it is grabbing the name of v, if “Name” is a part in the UI please rename it.

I am showing all of it. I am only trying to get it to print something for now. The problem is that there will be like 50 borders and i don’t want to create a function for every one.

Wait, you’re writing this in a core script? Oh boy.

Maybe try write a different empty local script inserted from the explorer, into the GUI, and then reference the GUI in the code.

Also, can we see your explorer menu, maybe something is going on there.

no… he named his script “CoreScript”

1 Like

The name of the UI is Border there shouldn’t be a problem

No, when detecting MouseHovering, you need to index an object not a name, because that is a string, so if the name of the UI is “Name” it needs to be changed because .Name gets the name of the parent aka a string.

50 borders!! :scream:

Perhaps there is a tutorial on YT, or on developer.Roblox.Com that talks about detecting when a mouse is on top of a border, I’m ain’t exactly sure how that work’s.

Yes, i need it to go find all the Buttons named “Border” and print some text.

this is what im talking about v.Name.MouseEnter is an issue, try v.MouseEnter

1 Like

If you’re trying to find all the button’s named “Border” probably use a :GetAllChildren("Border") and it should return all the children named “Border”

Here is a link to the same type of game I am making: Computer Mouse Game

:GetAllChildren() is not apart of roblox coding

Then GetChildren() Excuse moi, haven’t developed for a while. :man_facepalming:

There are no variables you can enter into GetChildren()

his code is perfectly fine using pairs, he needs to use v.MouseEnter not v.Name.MouseEnter

v.MouseEnter give this error: MouseEnter is not a valid member of ScreenGui “StarterGui.ScreenGui”

This is not how you should be handling this.

You seem to have a misunderstanding of the purpose that a function serves. There is no reason to wrap all of this inside of a while loop.

For simplicity sake, this is how I would organize:
image

You should avoid handling other UI objects that are not borders if you do not need to.

The code inside of the handler script could look something like this:

for _,v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Border" then
		v.MouseEnter:Connect(function()
			print('GAME OVER!')
		end)
	end
end

This code will attach a function to each border piece that activates once MouseEnter occurs.

3 Likes