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

Making a GUI move when your mouse hovers over it issues? [closed]

Asked by
Bman8765 270 Moderation Voter
9 years ago

Hi there, I'm currently working on a localscript which handles a large variety of features when handling the "Main GUI' for the game. Here is what the script should be doing, it should be moving a GUI button a tiny bit whenever the user moves his mouse over the button but it should then go back to the original position after the user's mouse leaves the area. I have 2 buttons that do this and every once and a while the buttons will mess up or error forgetting to go back or completely fly off the screen. It works fine if you are a gentle grandma learning how to use the internet but if you are a crazy kid (the entire roblox population pretty much) I could easily see this becoming an issue which is why I need suggestions on how to do it.

Below is the code (inside a localscript), this is not the entire script but it is all that you need to solve this problem. joinGame variable and customizeCharacter variable are both defined and located at the top of the script (not shown below) and work just fine so it is not a problem with the declaration of the textbuttons

--Variables below--
movingatm = false
joinGameOut = false
customizeCharacterOut = false

--joinGame button events below--

function clickedjoinGame()
    --Add joining and info here ;D
end

function enteredjoinGame()
    if joinGameOut == true then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end
    movingatm = true
    joinGameOut = true
    for xmove = 1,10 do

        joinGame.Position = joinGame.Position + UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false
end

function leftjoinGame()
    if joinGameOut == false then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end 

    movingatm = true
    joinGameOut = false
    for xmove = 1,10 do

        joinGame.Position = joinGame.Position - UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false   

end

joinGame.MouseButton1Down:connect(clickedjoinGame)
joinGame.MouseEnter:connect(enteredjoinGame)
joinGame.MouseLeave:connect(leftjoinGame)
------------------------------------------------
--customizeCharacter button events below--
function clickedcustomizeCharacter()
    --Insert character customization here
end

function enteredcustomizeCharacter()
    if customizeCharacterOut == true then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end
    movingatm = true
    customizeCharacterOut = true
    for xmove = 1,10 do

        customizeCharacter.Position = customizeCharacter.Position + UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false
end

function leftcustomizeCharacter()
    if customizeCharacterOut == false then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end 

    movingatm = true
    customizeCharacterOut = false
    for xmove = 1,10 do

        customizeCharacter.Position = customizeCharacter.Position - UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false   

end

customizeCharacter.MouseButton1Down:connect(clickedcustomizeCharacter)
customizeCharacter.MouseEnter:connect(enteredcustomizeCharacter)
customizeCharacter.MouseLeave:connect(leftcustomizeCharacter)
0
Look up tweening in the wiki. EzraNehemiah_TF2 3552 — 9y
0
WOw that seems really interesting, I'm going to experiment with it now and I'll come back if I find a better working version Bman8765 270 — 9y

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
Bman8765 270 Moderation Voter
9 years ago

Thanks to @LordDragonZord I realized a much easier way to manage this, tweening (found here http://wiki.roblox.com/index.php?title=API:Class/GuiObject/TweenPosition ) Here is a small explain of how I changed it:

BEFORE:

function enteredjoinGame()
    if joinGameOut == true then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end
    movingatm = true
    joinGameOut = true
    for xmove = 1,10 do

        joinGame.Position = joinGame.Position + UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false
end

function leftjoinGame()
    if joinGameOut == false then
        return;
    end

    if movingatm == true then
        repeat wait() until movingatm == false
    end 

    movingatm = true
    joinGameOut = false
    for xmove = 1,10 do

        joinGame.Position = joinGame.Position - UDim2.new(0.001,0,0,0)      

        game:GetService("RunService").RenderStepped:wait()
    end
    movingatm = false   

end

AFTER:

function enteredjoinGame()
    joinGame:TweenPosition(UDim2.new(.03, 0, 0.15, 0), "Out", "Quad", .1, true)
end

function leftjoinGame()
    joinGame:TweenPosition(UDim2.new(-.005, 0, 0.15, 0), "Out", "Quad", .1, true)
end
0
Do not write an answer on your own post. FearMeIAmLag 1161 — 9y
Ad