TextLabel position weirdly not updated

Hello! Not sure exactly why my script wouldn’t work.
It’s supposed to place a small text label at the current mouse position when hovering over a button.
Everything but the actual updating of position works. I could successfully print reasonable numbers for the coordinates, the loop ran and then stopped at the desired moment, etc.

local UserInputService = game:GetService("UserInputService")
local Tip = script.Tip

script.Parent.MouseEnter:Connect(function()
	local MouseHovers = true
	while MouseHovers do
		if not Tip.Visible then Tip.Visible = true end
		local Pos = UserInputService:GetMouseLocation()
		print(Pos.X," ", Pos.Y - 36)
		Tip.Position = UDim2.fromOffset(Pos.X, Pos.Y - 36) -- -36 because of the topbar
		wait()
		script.Parent.MouseLeave:Connect(function()
			MouseHovers = false
		end)
	end
end)

Any help?

To not reply in particular to every comment

I initially went with the way everyone recommended. It still failed to work, so I switched it to the way I posted on this topic.
local UserInputService = game:GetService("UserInputService")
local Tip = script.Tip
local MouseHovers = true

script.Parent.MouseEnter:Connect(function()
	MouseHovers = true
	print(MouseHovers)
	while MouseHovers do
		Tip.Visible = true
		local Pos = UserInputService:GetMouseLocation()
		print(Pos.X," ", Pos.Y - 36)
		Tip.Position = UDim2.fromOffset(Pos.X, Pos.Y - 36) -- -36 because of the topbar
		wait()
		
	end
end)

script.Parent.MouseLeave:Connect(function()
	MouseHovers = false
	print(MouseHovers)
end)

Edit #2: Not sure if Hierarchy matters here, as no errors pop up or something along the lines of that.
image

Edit #3: The issue has been scaled back to just the text refusing to load in a test, but working if I copy it over directly in Studio. I have checked both Archivable, Visible, etc, but it never works…

Not sure what the problem is but, I don’t think your .MouseLeave function should be defined inside the while loop.

That was the only solution I both found and got to work.

With this only happening one at a time, and it being local, I don’t suspect a lot of lag from this.

Define the MouseHovers variable outside .MouseEnter and both will be able to see and modify it.

so in the end it should be something like this:

local UserInputService = game:GetService("UserInputService")
local Tip = script.Tip
local MouseHovers = false --by default

script.Parent.MouseLeave:Connect(function() 
		MouseHovers = false
end)

-- moved it in front of Mouse.Enter because of the line reading system
-- not sure if that matters or no tough

script.Parent.MouseEnter:Connect(function()
	MouseHovers = true
	while MouseHovers == true do -- so it matters if it hovers or not 
        -- "While MouseHovers do" checks if MouseHovers exists
		if not Tip.Visible then Tip.Visible = true end
		local Pos = UserInputService:GetMouseLocation()
		print(Pos.X," ", Pos.Y - 36)
		Tip.Position = UDim2.fromOffset(Pos.X, Pos.Y - 36) 
		wait()
	end
end)

Tried it. No difference.
It doesn’t matter.

local UserInputService = game:GetService("UserInputService")
local Tip = script.Tip
local MouseHovers = false

script.Parent.MouseLeave:Connect(function() 
		MouseHovers = false
end)

script.Parent.MouseEnter:Connect(function()
	MouseHovers = true
	while MouseHovers == true do -- so it matters if it hovers or not 
        -- "While MouseHovers do" checks if MouseHovers exists
		if Tip.Visible == false then Tip.Visible = true end -- once again while not Tip.Visible checks for consistency
		local Pos = UserInputService:GetMouseLocation()
		print(Pos.X," ", Pos.Y - 36)
		Tip.Position = UDim2.fromOffset(Pos.X, Pos.Y - 36) 
		wait()
	end
end)

made a change (again).
try it

Still fails to work.

I have found something interesting though, the TextLabel just refuses to appear. If I copy it out of the test and paste it back in studio it turns visible.
Positioned weirdly because I tried to change some Y values outside your solution.
image
^ Studio
v Test
image

Roblox is currently a little down right now, so that might be the issue. I can’t even save my stuff to Roblox, and it keeps spamming saved failed like bruh.

Roblox works fine for me right now.

I also have other reasons to believe it’s an issue with the script, such as me not ever getting something like this to work. Tried multiple times in the past…

Your main issue here might be that you pre-defined the Tip, and then you tried to use the pre-defined Tip with Tip.Position.When I work with GUIs I always define it EXACTLY like script.Parent.Parent.(whatever im looking for) and then do my thing because sometimes it doesn’t work as intended when pre-defined.

    • So basically what I’m saying is use Script.Tip.Position instead of Tip.Position

Also, one more thing don’t you think an offset of 36 is too much?? That might also account for the message to just be gone from the screen. Try 0.1

Apparently you no longer can place TextLabels inside scripts which are under ScreenGUIs. They just don’t show up. When and why did this change happen, or if it ever was possible, no idea…

But thank you everyone for the support and solutions you gave me.