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

Why does my Animation goes out of the screen more you click the Button?

Asked by 8 years ago
Edited 8 years ago

Where it is or where I have it game.StarterGui.ScreenGui.Frame & game.StarterGui.ScreenGui.TextButton.Script

The TextButton.Text.Value = Menu

Test Place: www.roblox.com/games/658003394/Open-Close-Animation-Gui-Test-Place

The Script: (Normal)

01debounce = false
02 
03script.Parent.MouseButton1Click:connect(function()
04    if not debounce then
05        debounce = true
06        if script.Parent.Text == "Menu" then
07            -- Open function
08            script.Parent.Parent.Frame.Visible = true
09            for i = 1,25 do
10                script.Parent.Parent.Frame.Size = script.Parent.Parent.Frame.Size + UDim2.new(0.02,0,0,0)
11                wait()
12            end
13            for i = 1,8 do
14                script.Parent.Parent.Frame.Position = script.Parent.Parent.Frame.Position - UDim2.new(0,0,0,0)
15                wait()
View all 41 lines...
0
Hm HeyTheoryz 0 — 8y

1 answer

Log in to vote
2
Answered by
Troidit 253 Moderation Voter
8 years ago
Edited 8 years ago

Hi, I can see you've done a lot of number crunching to create your GUI, but there is a much simpler way to move GUI's or resize them without using a for loop.

Here's an example of a script I created that moves a GUI from off screen to on screen.

01button = script.Parent
02shop = button.Parent.Shop
03open=false
04 
05button.MouseButton1Click:Connect(function()
06    if not open then
07        open=true
08        shop:TweenPosition(UDim2.new(0.5,-250,0.5,-100),"Out","Quad",1)
09    else
10        open=false
11        shop:TweenPosition(UDim2.new(0.5,-250,-0.5,-100),"Out","Quad",1)
12    end
13end)

If you'll notice, instead of using for loops to change the position, I use a cool API called TweenPoisition(). What it does is essentially animate the GUI from where it is to where you give the UDim2.new() position.

Let's say I had a GUI sitting of screen so it's location was (-0.5,0,0,0) and I wanted to move it into view for the player to see. The first step would be to define what the GUI is that you're moving. In my case it's a frame titled Shop.

1shop:TweenPosition()

Next you want to give the location that you want it to take the GUI to.

1shop:TweenPosition(UDim2.new(-0.5,0,0,0))

That's not all though. We can also set the styles of the wait the GUI eases in our out, or both. As well as setting the EasingStyle for how it'll look sliding. I like to pick Quad for this one. (Here is an animated list Roblox made of all the different easing styles.)

1shop:TweenPosition(UDim2.new(-0.5,0,0,0),"Out,","Quad")

You can also set how long it takes for the animation to float to the end point. It's default is one second.

1shop:TweenPosition(UDim2.new(-0.5,0,0,0),"Out,","Quad",1)

You can also use TweenSize() to tween the size instead or do both position and size with TweenSizeAndPosition()

You can read more about Tweening on the wiki page here.

Ad

Answer this question