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

How do you make it so when the user's mouse is idle, it does something when it is...?

How do you make it so when the user's mouse is idle, it does something when it is touching the text label? Thanks!

player.PlayerGui.ScreenGui.TextLabel.MouseEnter:connect(function()
	if player:GetMouse().Idle then
		
	end
end)

1 answer

✓ Accepted answer

You could connect and disconnect the idle event while the mouse is inside the text label but this may not be the best solution, but a solution nevertheless.

Example:-

local mouse = game.Players.LocalPlayer:GetMouse()
local con = nil

local textLabel = player.PlayerGui.ScreenGui.TextLabel

local function idle()
	print('idle')
end

textLabel.MouseEnter:Connect(function()
	con = mouse.Idle:Connect(idle) -- connect the idle event
end)

textLabel.MouseLeave:Connect(function()
	con:Disconnect() -- disconnects the idle event
end)

I hope this helps, please comment if you do not understand how / why this code works.

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