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