This is the code I tried.
-- LOCAL VARIABLES -- Player =game.Players.LocalPlayer; Mouse =Player:GetMouse(); MouseDefaultIcon ="http://www.roblox.com/asset/?id=265193813" MouseHoverIcon ="" MouseClickIcon ="" Mouse.MouseEnter:connect(function() if Mouse.MouseEnter.className == "TextButton" or "ImageButton" then Player.Character.Health = 0 end end)
I wanted to make this so I don't have to re-script the MouseIcon every for every ImageButton or TextButton.
I did Player.Character.Health = 0 just to test if it works. It does not currently, please help! Thanks!
Solution:
GUI elements have an event called MouseEntered()
. It does exactly what the name implies; fires when the player's mouse enters the GUI object.
Make sure you're using a local script with local player. The reason for this is GUIs and the mouse are client-sided; it only pertains to the player that is running the script. The server does not control your mouse; you control your mouse.
Application:
player = game.Players.LocalPlayer game.PlayerGui.TextButton.MouseEnter:connect(function() -- Fires when mouse enters TextButton (or any GUI element such as ImageButton) player.Character.Humanoid.Health = 0 -- Kills the player end)
And if you want, there's also another event called 'MouseLeave'. It does the exact opposite -- fires when the player's mouse leaves the GUI element.
Additional resources: Wiki page for MouseEnter Wiki page for MouseLeave
I hope this helps and if you have any further questions or comments, let me know! :)