generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: TweenPosition (OnClick)

Previous Thread :: Next Thread 
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
02 Nov 2015 04:30 PM
Soooo, i have a shop GUI.
There is an Open Textbutton that opens the shop (frame) with a tween (sliding in from the side of the screen). Here is how the localscript(for the "Open Shop" Button) looks so far:
======================================================================================
local Closed = true

function onButtonClicked ()
if Closed then
script.Parent.Parent.ShopFrame:TweenPosition(UDim2.new(0,5,0.305),"InOut","Quad", 0.5,true)
else
script.Parent.Parent.ShopFrame:TweenPosition(UDim2.new(0,-5,0.305),"InOut","Quad", 0.5,true)
end
end
script.Parent.MouseButton1Click:connect(onButtonClicked)
======================================================================================
Now i want to make the Close button slide the Shop frame away from the screen.
Basically there should be probably 2 localscripts right?
One for the "Open Shop" tween to slide in,
and second for "Close Shop" tween to slide out.
Btw: the "Close Shop" Button is inside the frame of the Shop.
I tried to copy the same localscript to the "Close Shop" TextButton but it seemed not to work at all...

~~Modecom2
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 03:19 AM
I really need help :(
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 10:27 AM
I don't want to spam but really does anybody even knows how to do it??? :(
It must be really simple i believe. I'm a beginner
Report Abuse
brados123 is not online. brados123
Joined: 24 Nov 2012
Total Posts: 2143
03 Nov 2015 10:31 AM
script.Parent.Mousebutton1down:Connect(function()

script.Parent:TweenPosition(UDim2.New(--) -- this is the position for it to go.

end)
Report Abuse
brados123 is not online. brados123
Joined: 24 Nov 2012
Total Posts: 2143
03 Nov 2015 10:32 AM
oh and obviously add in after position:


(--), "Out", "Quad", 1)
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 10:34 AM
It is for the close button to work, right?
Does this : script.Parent.Mousebutton1down:Connect(function()
Have to be on the beginning of the localscript?
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 10:46 AM
Doesn't work :/
Report Abuse
Botchan is not online. Botchan
Joined: 14 Jun 2015
Total Posts: 269
03 Nov 2015 10:46 AM
script.Parent.MouseButton1Down:connect(function() end) is an anonymous function with no name which says the script's parent (hence script.Parent) is pressed with the left clicked mouse button and held/clicked, it will connect to the function and launch the event(s).

It does not have to be in the beginning of the script but make sure everything is defined within the script.
Report Abuse
NefariusNightmare is not online. NefariusNightmare
Joined: 01 Aug 2013
Total Posts: 94
03 Nov 2015 11:41 AM
local open = true
local activated = false

function Open()
for x = 5,0,-0.1 do
wait(0.01)
script.Parent.Position = script.Parent.Position - UDim2.new(math.sinh(0.005),0,0,0)
end
script.Parent.Text = "Close Shop"
open = true
end
function Close()
for x = 5,0,-0.1 do
wait(0.01)
script.Parent.Position = script.Parent.Position + UDim2.new(math.sinh(0.005),0,0,0)
end
script.Parent.Text = "Open Shop"
open = false
end


script.Parent.MouseButton1Click:connect(function()
if activated == false then
if open == true then
activated = true
script.Parent.Sound:Play()
Close()
activated = false
elseif open ~= true then
activated = true
script.Parent.Sound:Play()
Open()
activated = false
end
elseif activated == true then return nil
end
end)

Feel free to study it. Or judge it, lol. But that's how I make shops. If you need to know how to do it for multiple parts inside a ScreenGui let me know. I do hope this is helpful. ;p
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 11:55 AM
Where should i place the script?
-Inside the Open Shop Textbutton
-Inside the GUI
-Inside the Shop Frame

?????
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
03 Nov 2015 11:57 AM
I just want to know what a "Close shop" TextButton with tween (slide out of screen) looks like.... that's it
Report Abuse
CreativitiesUnity is not online. CreativitiesUnity
Joined: 08 Nov 2014
Total Posts: 1281
03 Nov 2015 12:10 PM
it just slides out simply, look it up if you have to?




CU
Report Abuse
NefariusNightmare is not online. NefariusNightmare
Joined: 01 Aug 2013
Total Posts: 94
03 Nov 2015 04:18 PM
I will send some Giazo's of what I have.

https://gyazo.com/848a804818c2f2e1c58f8af34f28969f

I don't use Tweening yet, but I do believe my methods suffice for a shop GUI. No matter what, the parent containing the children; (details, buttons, images, etc) they will move with it. All you have to do is move the parent. Which in this case, is "TextButton".

This is what it should look like...
https://gyazo.com/1e4fd8268b4d2d04ff82254b57bd510d

Hope this helps!

"Anger sedates your mind, now your body leads with no head"
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
04 Nov 2015 09:57 AM
So you say that this script will manage to open and close the shop (even when there are 2 buttons, 1 for open 2 for close) with a tween?
Report Abuse
NefariusNightmare is not online. NefariusNightmare
Joined: 01 Aug 2013
Total Posts: 94
04 Nov 2015 10:21 AM
It will open and close the entire shop with just one button. If you want to add another button to close it or open it, instead of just keeping one, you'll have to change up the script.

"TextButton" is a child of ScreenGui, when "TextButton" is moved, all children of "TextButton" are moved with it.
So make sure, if you do add another button, to keep all of it in "TextButton". Otherwise you'll have to add another line to the script, which is more hassle, less organized, and reduced performance.
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
04 Nov 2015 10:57 AM
Ok! I must try that ASAP!
Thanks a lot for the help!!!!

~~Modecom2
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
04 Nov 2015 11:41 AM
Sooooo, it should look something Like this? :

https://gyazo.com/d60b1f7c0ef15b2128f718e27fc5e8e1
Report Abuse
iMung is not online. iMung
Joined: 11 Jul 2013
Total Posts: 328
04 Nov 2015 12:05 PM
Don't name a function which is a keyword name. Example:

function OnClick(gui)
gui:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 2)
end

OnClick(script.Parent.Frame)
Report Abuse
iMung is not online. iMung
Joined: 11 Jul 2013
Total Posts: 328
04 Nov 2015 12:08 PM
I'll give you a better version of code.

Enabled = false -- Its a debounce

script.Parent.TextButton.MouseButton1Click:connect(function()
if not Enabled then
Enabled = true
script.Parent.Frame:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 1)
elseif Enabled then
Enabled = false
script.Parent.Frame:TweenPosition(UDim2.new(0,0,0,0), "Out", "Quad", 1)
end
end)

So basically what the UDim2.new means is the coordinates of the GUI position, then "Out" means the direction, then the number at the last argument is the time it takes to get there, the override.
Report Abuse
NefariusNightmare is not online. NefariusNightmare
Joined: 01 Aug 2013
Total Posts: 94
04 Nov 2015 01:40 PM
@iMung
I tried yours, but I fail to see the efficiency in it. Your script is much shorter, but I decided to dabble with it myself. Whereas I don't do tweening (haven't the knowledge of it yet), there were errors I had that I fixed in my script. Which is why it was so much larger in lines.
Report Abuse
brados123 is not online. brados123
Joined: 24 Nov 2012
Total Posts: 2143
04 Nov 2015 03:46 PM
nef, tweening is super easy trust me.



currently for gui's, there is three kinds of tweening;

tweensize
tweenposition
tweensizeandposition



let me give you some example script.

so, lets say you have a gui, that you want to slide in from the left.

so, set a un-named function for;

script.Parent.MouseButton1Down:connect(function()




end)

now say you want to bring in from the side, you have to position it at something far away to the left, like 0,-500,0,300. this positions it roughly invisible, but centre(its really far from the left).

so, now all your going to do is inbetween the code i put up there, do this to reposition size.

script.Parent.MouseButton1Down:connect(function()

script.Parent:TweenPosition(UDim2.New(0,400,0,300), "Out", "Quad", 1)




end)






thanks guys
Report Abuse
NefariusNightmare is not online. NefariusNightmare
Joined: 01 Aug 2013
Total Posts: 94
04 Nov 2015 04:24 PM
@brados123
You're using the Offset UDim- but I see your point.

Offset can cause graphical glitches and bugs for any different screen resolution other than your own.
i.e... you have a desktop computer, it will look different for a laptop or a phone because of it's offset was based on your resolution. Using offset doesn't resize or adapt to the varying monitor resolution, whereas not using offset does.
Report Abuse
iMung is not online. iMung
Joined: 11 Jul 2013
Total Posts: 328
04 Nov 2015 04:35 PM
I only use Scale because it won't glitch your screen. But I am pretty sure my script works. I have that script memorized in my head because I make it so often.
Report Abuse
modecom2 is not online. modecom2
Joined: 18 Jul 2009
Total Posts: 114
05 Nov 2015 11:54 AM
OK, OK I'll try them :)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image