Hey,
I’ve been trying to get whenever the mouse icon changes.
The function never starts, i tried by hovering a button to make it change but it doesn’t start anyway.
--Servizi
local UIS = game:GetService("UserInputService");
local Giocatori = game:GetService("Players");
--Variabili
local Giocatore = Giocatori.LocalPlayer; --player
local mouse = Giocatore:GetMouse(); -- mouse
function Muove()
--this one works
end
function Cambia()
print("ok") --never gets printed
end
mouse:GetAttributeChangedSignal("Icon"):Connect(Cambia)
mouse.Move:Connect(Muove)
It is impossible to do this directly, you need to check the mouse icon each time (loop) and compare it with the previous one, if they are different, then they have changed and call the function.
You could try to check the Mouse.Target every time Muove is ran, to see if the mouse is hovered over your button, and change the icon from there. If you have more than 1 button, consider using CollectionService to detect if a target has a Button tag on it. You can ask me about that if you’re not sure how to use it.
--Servizi
local UIS = game:GetService("UserInputService");
local Giocatori = game:GetService("Players");
--Variabili
local Giocatore = Giocatori.LocalPlayer; --player
local mouse = Giocatore:GetMouse(); -- mouse
local ButtonIcon -- Make this your button icon asset
local DefaultIcon = 'rbxasset://SystemCursors/Arrow' -- Just the default roblox Icon
local Button -- Make this your physical button Part in the workspace
function Muove()
if mouse.Target == Button and UIS.MouseIcon ~= ButtonIcon then
UIS.MouseIcon = ButtonIcon
elseif mouse.Target ~= Button and UIS.MouseIcon == ButtonIcon then
UIS.MouseIcon = DefaultIcon
end
end
-- Since the Mouse object is planned to get deprecated in the future, use the new UserInputService functions
UIS.InputChanged:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
Muove()
end
end)
I think you can be more resourceful in your replies, seems like you’re only telling the person what they cannot do, and not providing much solutions for them. Perhaps, you can give them a code example to explain the solution you provided. This could help them solve their issues much better.
I don’t think this will work since it needs a UI button and not a BasePart.
I suggest using MouseEnter/MouseLeave for the button, that would be the best option.