Need help with RunService and GUIs

Hello! Apologies if I do something wrong while making this post, it’s my first time using the DevForum.

I’m currently trying to make a tooltip GUI; once the player’s mouse hovers (.MouseEnter) over the frame, another frame is made visible and follows the player’s cursor. In an opposite fashion, once the cursor leaves (.MouseLeave) the frame, the frame that was previously following the player’s mouse is made invisible and stops following.
This is what I achieved so far:
mousegui

As you can see, the .MouseEnter portion of the script works; however, once the cursor leaves the white frame, the blue one keeps following it and is still visible. I also noticed that the position of the blue frame doesn’t match perfectly with the cursor’s tip and I’m not sure on how to fix it.
Here is the Local Script:

local frame = script.Parent
local mouseFrame = script.Parent.Parent.mouse
local UserInputService = game:GetService("UserInputService")
mouseLocation = UserInputService:GetMouseLocation()
local mouseFramePos = mouseFrame.Position
local RunService = game:GetService("RunService")

frame.MouseEnter:Connect(function()
	function moveGuiToMouse()
		mouseLocation = UserInputService:GetMouseLocation()
		mouseFrame.Visible = true
		mouseFrame.Position = UDim2.fromOffset(mouseLocation.X, mouseLocation.Y)
	end
	RunService:BindToRenderStep("moveGuiToMouse", 1, moveGuiToMouse)
end)

frame.MouseLeave:Connect(function()
	RunService:UnbindFromRenderStep(moveGuiToMouse)
	mouseFrame.Visible = false
	mouseFrame.Position = mouseFramePos
end)

I’m assuming that, because the :BindToRenderStep portion of the code is above the :UnbindFromRenderStep one, the .MouseLeave function never gets triggered? I don’t have much experience with RunService and the Wiki didn’t help much unfortunately. I also get no errors from the output window. This is how the explorer looks by the way:
image

Thank you to those who will try to help!

Solution for the corner of the blue GUI not matching with the cursor’s tip by @SloppyBanana225. :slight_smile:

it doesn’t fit the tip due to it’s anchorpoint, try making it 0.5, 0.5. Also try to change position on it to 0.5,0.5 too.

1 Like

RunService:UnbindFromRenderStep("moveGuiToMouse")
And, could have set the frame visibility to true outside the moveGuiToMouse
And, make the function local!

2 Likes

Thank you!
I tried setting the anchor point to 0.5,0.5 and this is what it looked like:
image
I also tried 1,1 and it’s much better:
image
What if I wanted the tip to match the opposite corner though? -1,-1 doesn’t seem to work.

Also try to change position on it to 0.5,0.5 too.

Doesn’t make much difference? I’m a bit confused lol.

The anchor point at 0.5,0.5 means that it’s anchorpoint is no longer top left and now it is in the center so 1,1 would be top right.

1 Like

Omg thank you so much! Works perfectly now.
How come RunService:UnbindFromRenderStep("moveGuiToMouse") works but not RunService:UnbindFromRenderStep(moveGuiToMouse)?

And, could have set the frame visibility to true outside the moveGuiToMouse
Confused by this, could you elaborate? ^^"

No quotations, since you didn’t mark it. Or rather add a local moveGuiToMouse

1 Like

RunService:UnbindFromRenderStep accepts strings, not functions.

frame.MouseEnter:Connect(function()
	local function moveGuiToMouse()
		mouseLocation = UserInputService:GetMouseLocation()
		mouseFrame.Position = UDim2.fromOffset(mouseLocation.X, mouseLocation.Y)
	end
	mouseFrame.Visible = true
	RunService:BindToRenderStep("moveGuiToMouse", 1, moveGuiToMouse)
end)

Also is the blue square rotated? Usually with an anchor point of 1,1 it should be the bottom right corner.

2 Likes

I agree, it might be rotated. Make sure that it’s not it could affect something if you tried to use it.

RunService:UnbindFromRenderStep accepts strings, not functions.

Got it, thank you! :slight_smile:

Also is the blue square rotated? Usually with an anchor point of 1,1 it should be the bottom right corner.

Nope, it’s not.
image

Cool, glad we could help, Have a good day!

1 Like

I am unable to reproduce the same effects.
Anchor points are working as they should for me.
Although I am unsure if this affects anything, but are the square’s ancestors rotated?

Mhh, nope. None of them is. A bit odd, but not a big deal I suppose. ^^"