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

How to make this ImageLabel Rotate?

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)

1 comment

0

Your Hierarchy does not match "game.StarterGui.Main.Image".

2 answers

2 Problems:

  • You're adding the rotation to the rotation of a different gui, which will not move the rotation of the refresh gui
  • You used MouseEnter on Leave instead of MouseLeave

#MouseLeave(int x, int y) Runs when the mouse leaves a gui object.

GUI.MouseLeave:connect(function(x,y)
	print("Mouse left at "..x..","..y..".")
end)

#Final Product

--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!

1 comment

0

Wow, ty. I kinda feel ashamed after this answer. I got frustrated doing something else so I posted this question without checking my code. Thanks!

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)

5 comments

0

It would work, you're wrong...

0

Actually it wouldn't. Go ahead and test it yourself. I'll wait right here for you

0

No, you misunderstood me, I meant his version of the code would work fine, if he made no mistakes.

0

His code would be stuck in the loop. The loop doesn't break because an event triggered, it continues. OP only wants it to spin when the mouse is on the label, not when it is off of it.

0

I worded my post better. You probably assumed I meant that it had errors. I know it doesn't, it just wont do as he fully intended.

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