Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this ImageLabel Rotate?

Asked by
xPolarium 1388 Moderation Voter
8 years ago

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)
0
Your Hierarchy does not match "game.StarterGui.Main.Image". EzraNehemiah_TF2 3552 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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!

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! xPolarium 1388 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

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)

0
It would work, you're wrong... EzraNehemiah_TF2 3552 — 8y
0
Actually it wouldn't. Go ahead and test it yourself. I'll wait right here for you Legoman654 100 — 8y
0
No, you misunderstood me, I meant his version of the code would work fine, if he made no mistakes. EzraNehemiah_TF2 3552 — 8y
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. Legoman654 100 — 8y
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. Legoman654 100 — 8y

Answer this question