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:
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:
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.
RunService:UnbindFromRenderStep("moveGuiToMouse")
And, could have set the frame visibility to true outside the moveGuiToMouse
And, make the function local!
Thank you!
I tried setting the anchor point to 0.5,0.5 and this is what it looked like:
I also tried 1,1 and it’s much better:
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.
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? ^^"
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?