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

(?) So I'm trying to make my gui move to the middle then go to the right side.

Asked by 4 years ago

I want my gui to move to the middle then to right side of the screen then it disappear but it only moves to the middle wait 5 second and disappear but I want it to move to the middle wait 5 seconds and then move to the right side here's my script (this is for my murder type game)

Script

    chosen.PlayerGui.Picker.Background.Position = UDim2.new(0.1, 0, 0.25, 0) 
    chosen.PlayerGui.Picker.Background:TweenPosition(UDim2.new(0.4, 0, 0.25, 0))
    wait(5)
    chosen.PlayerGui.Picker.Background:TweenPosition(UDim2.new(0.4, 0, 0.25, 0))
    chosen.PlayerGui.Picker.Background.Visible = false

1 answer

Log in to vote
1
Answered by 4 years ago

It's because it's setting the Visible property to false before the tween completes, I think you tought the script pauses during the tween, but no, it doesn't. To fix it, we can use the callback argument in the TweenPosition function. Here is an example of how you need to do it:

chosen.PlayerGui.Picker.Background:TweenPosition(UDim2.new(number x, number y, number z), "Out", "Sine",1,true,functiontorunwhentweencompletes)

Here is an explaining: the first argument is the position to tween to (in the Udim2.new function). Then, we need to put the next arguments outside of the parenthesis of the Udim2.new function, wich are: easingDirection(in this case, "Out"), easingStyle(in this case, "Sine"), time(seconds for it to complete, should not be a number <0), override(true if you want it to override other tweens, false if you don't), and callback, wich, if you have a set up function, you can enter it there so it runs after the tween is completed, wich we can use to set the Visible property to false. So your script can look like that:

local function setVisibility()
    chosen.PlayerGui.Picker.BackGround.Visible = false
end 
chosen.PlayerGui.Picker.Background:TweenPosition(UDim2.new(0.4, 0, 0.25, 0), "set your easingDirection", "setyoureasingStyle",seconds for the tweeen to complete)
wait(5)
chosen.PlayerGui.Picker.Background:TweenPosition(UDim2.new(0.4, 0, 0.25, 0),"set your easingDirection", "setyoureasingStyle",seconds for the tweeen to complete,setVisibility)

Hereis a wiki link for the easing direction and styles: https://developer.roblox.com/en-us/articles/GUI-Animations (Click Additional Options in the top right corner)

Ad

Answer this question