How do i make it so the frame follows the players mouse position?

I followed a tutorial where it worked for him but it doesn’t work for me.

Explorer:

ViewDetailsFrame LocalScript:

local frame = script.Parent.Parent
local petDetails = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

frame.MouseEnter:Connect(function()
	petDetails.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	petDetails.Visible = true
	
	print(petDetails.Visible)
end)

frame.MouseMoved:Connect(function()
	petDetails.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	petDetails.Visible = true
	
	print(petDetails.Visible)
end)

frame.MouseLeave:Connect(function()
	petDetails.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	petDetails.Visible = false
	
	print(petDetails.Visible)
end)

pls help

hello!

this is probably because the pet details frame is being positioned relative to the parent frame “PetFrame1”

the easiest way to see this is in action is by setting the position of the pet details to (0, 0, 0, 0) while it is inside of the pet frame, and when it is parented to the screen gui.
inside of the screen gui, it appears in the top left corner of the screen, while when it is parented to the pet frame it is in the top left of the frame instead.

the easiest way to fix this is by subtracting the mouse position by the parent frame’s position.
you should change every line where you change the position to:

petDetails.Position = UDim2.new(0,mouse.X - frame.AbsolutePosition.X,0,mouse.Y - frame.AbsolutePosition.Y)

omg thank you so much been stressing abt this for hours now thank you : )

is there to way to make it so the frames corner isnt exactly on the location of the mouse?

yes, you can do that by changing the anchor point property of the pet details frame to (1,1) : )

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.