So I'm making a refresh button by using a ImageLabel. I've gotten the main code down to refresh a player and spawn them back in their previous spot. My problem is that my ImageLabel has a "Refresh" icon and I want it to rotate when the player moves their mouse over the ImageLabel.
My GUI and Hierarchy of it:
GUI
Hierarchy
Here's my code and I think I'm not using something right:
--LOCAL SCRIPT INSIDE A IMAGELABEL function Entered() while true do wait(0.1) script.Parent.Rotation = game.StarterGui.Main.Image.Rotation + 1 end end function Leave() script.Parent.Rotation = 0 end script.Parent.MouseEnter:connect(Entered) script.Parent.MouseEnter:connect(Leave)
2 Problems:
Runs when the mouse leaves a gui object.
GUI.MouseLeave:connect(function(x,y) print("Mouse left at "..x..","..y..".") end)
--LOCAL SCRIPT INSIDE A IMAGELABEL function Entered() while true do wait(0.1) script.Parent.Rotation = script.Parent.Rotation + 1 end end function Leave() script.Parent.Rotation = 0 end script.Parent.MouseEnter:connect(Entered) script.Parent.MouseLeave:connect(Leave)
Hope it helps!
Your code wouldn't work as intended anyhow. You'd be stuck inside of the while loop so it would continuously spin even when the mouse exits. I recommend a repeat loop with some kind of local script setting. Here's something I typed out in a way you can understand it. Otherwise I would just create the events inside of eachother:
local hovering = false; function mouseEntered() hovering = true; repeat wait(1/45); script.Parent.Rotation = workspace.DistributedGameTime*125; until hovering = false; end function mouseLeft() hovering = false; end script.Parent.MouseEnter:connect(mouseEntered) script.Parent.MouseLeave:connect(mouseLeft)