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

Changing Position of TEXTButton until it reaches a certain scale?

Asked by
Bman8765 270 Moderation Voter
10 years ago

In my game there is a little menubutton on the left hand side of the screen, I want the menu button kinda tucked away but when a user puts his mouse over it it will slide out and show the full button and when he removes his mouse it will slide back. Basically when you put the mouse over it right now it just keeps sliding and will keep sliding every time you put your mouse over it until it goes off screen (also it wont go back because I have no clue how to add that) All I need is it to stop at a certain point (doesn't matter where you put it just point out that's what it is) and go back after removing the mouse for about 3 seconds.

Here is the code I have so far (this only includes the sliding forwards, I have no clue what I'll do about sliding back)

Menu = script.Parent
MenuButton = Menu.MenuButton
MenuPos = MenuButton.Position
MenuX = MenuPos.X.Scale
print("Pos of menuX is " .. MenuX)

if MenuX <= 0.5 then
    function OverMenuButton()
        for MenuPosition = 1, 20 do
            if MenuPosition <= 20 then 
                MenuButton.Position = MenuButton.Position +UDim2.new(0.01, 0, 0, 0) 
            end
            wait()
        end
    end
end

MenuButton.MouseEnter:connect(OverMenuButton)

If you guys could help, and give wiki links that would be great!

0
I have never used this before, so I can't really teach it, but try this: http://wiki.roblox.com/index.php?title=Tweening Perci1 4988 — 10y

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

A simple way to do this is to maintain a current x position of the menu button.

When the mouse is over, we add to x, when it's not, we remove from x.

mouseOver = false
x = 0

MenuButton.MouseEnter:connect(function()
    mouseOver = true
end)
MenuButton.MouseLeave:connect(function()
    mouseOver = false
end)

while wait() do
    if mouseOver then
        x = x + 0.01
    else
        x = x - 0.01
    end
     -- limit `x` to be between 0 and 0.5:
    x = math.min( 0.5 , math.max( 0, x ) )
    -- Use `x` to make a position:
    MenuButton.Position = UDim2.new(x , 0 , 0 , 0)
end

(Note this solution in general isn't mobile friendly; also that linear motion isn't very comfortable to watch but will work)

Ad
Log in to vote
0
Answered by
ipiano 120
10 years ago

As per Perci's comment, the tween method is a good way to do this. The motion won't be linear, and it doesn't allow quite as much of a degree of control, but everything is handled by the Roblox classes.

currentYPos = menuButton.Position.y.scale

MenuButton.MouseEnter:connect(function()
    menuButton:TweenPosition(UDim2.new(0.5, 0, currentYPos, 0), "Out", "Quad", 1, true)
end)

MenuButton.MouseLeave:connect(function()
        menuButton:TweenPosition(UDim2.new(0, 0, currentYPos, 0), "Out", "Quad", 1, true)

end)

See this link: http://wiki.roblox.com/index.php?title=TweenPosition

Answer this question