Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Move left and right hover "buttons" ?

I have a GUI that should move a textlabel back and forth when it has a mouse hovering over it, but no matter what I try, I cannot get it to move continuously, only when the mouse actually enters the object. I was wondering if there was a way to detect if the player's mouse is inside of a gui part and run some code if it is.

1 answer

✓ Accepted answer

If the gui is a simple rectangle then you could just get the position of the mouse and the boundaries of the gui. Like so:

local mouse = game.Players.LocalPlayer:GetMouse();
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel;

while wait() do
	if mouse.X <= gui.Position.X + gui.Size.X and mouse.Y <= gui.Position.Y + gui.Size.Y and mouse.X >= gui.Position.X and mouse.Y >= gui.Position.Y then
		--move code
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.