I need it so that when the player clicks the text button, "How To Play", another gui slides in from the right of the screen. My script isn't working, what's wrong with it or what do I need to type? Please help!
if script.Parent.MouseButton1Click then game.StarterGui.ImagePicture.HowToPlay:TweenPosition(UDim2.new(0.300, 0, 0.650, 0)) end
I have left an example code below.
local image = script.Parent:WaitForChild("ImageLabel") local button = script.Parent:WaitForChild("TextButton") button.MouseButton1Click:Connect(function() if image.Visible == false then image.Visible = true image:TweenPosition(UDim2.new(0.300, 0, 0.650, 0),"InOut", "Quad", 0.3) wait(0.3) else image:TweenPosition(UDim2.new(1, 0, 0.650, 0),"InOut", "Quad", 0.3) wait(0.3) image.Visible = false end end)
I hope this helped :)
If you would like further help just reply.
Hey DarkAssasin0, There are a few errors I noticed with your code. Well, 2 main errors anyway. Below I will go over the two errors and give you a wiki page and an example of what you can do to fix those errors.
if statement
. First off, the if statement
is completely wrong and very much so unnecessary. I can tell what you are trying to do from your if statement, which is to make this Gui tween when the user presses down on a certain Button. However, for this you use Events and Functions, not if statements
. The Button has an event of MouseButton1Click and you use that to connect a function, which will run when the Button is Left Clicked. Below is a personal example.local button = script.Parent -- Declares a variable for the button function tween_plz() -- A function named 'tween_plz' which will be later connected with the MouseButton1Down event. print("The tweening process is happening atm, muahahah") -- Prints "The tweening process is happening atm, muahahah". end -- end for the function button.MouseButton1Click:Connect(tween_plz) -- Connects the function to the event.
Your second error is your :TweenPosition() statement. Tweening has 6 arguments. 2 of them you can leave out but, the other 4 you have to add. The 4 of them are:
1. Position/Size or Position and Size depending on which one you are doing. 2. EasingDirection. (Controls the direction of the tween) 3. EasingStyle. (The way that it will act when it's tweened) 4. Float time. (The amount of time you want it to cover before it reaches the end.
local button = script.Parent -- Declares a variable for the button function tween_plz() -- A function named 'tween_plz' which will be later connected with the MouseButton1Down event. local gui_to_tween = script.Parent.Parent:WaitForChild("Tweening Gui") gui_to_tween:TweenPosition(UDim2.new() --[[ The position it needs to be tweened to--]], Enum.EasingDirection.In --[[ The direction it's going to tween to --]], Enum.EasingStyle.Quad --[[ The style the tweening is going to act when it's happening --]], 0.5 --[[ The amount of time the Gui will take to reach the tweening position. --]]) end -- end for the function button.MouseButton1Click:Connect(tween_plz) -- Connects the function to the event.
~~ KingLoneCat