How to make a gui object rise when clicked

How do I find the UDim2? I’m not very good at scripting.

Answered in the reply above! Just click on the link there. :slight_smile:

Basically just move the RadioImage where you want, go into its properties and in the Position property, there are 4 numbers, those are the 4 values t o put into an UDim2. Say you want it go up at 0.5 on the Y scale and 0.2 on the X scale, just do

local openPos = UDim2.new(0.2,0,0.5,0)

You need to replace ScreenGui with a reference to your actual screengui object. E.g. if the code is pasted in a LocalScript that’s parented to a screengui object, you would do script.Parent.

If you’re not sure about what a “reference to an object” is, this resource here might be of use to you : Learn Roblox

Did you put it so that the Radio image starts off closed? If so, you could try this out

local image = script.Parent

local open = false

local pos = image.Position

local closePos = pos
local openPos = UDim2.new(pos.X.Scale,pos.X.Offset,pos.Y.Scale - 0.1, pos.Y.Offset)

image.MouseButton1Click:Connect(function()
	local chosenPos = open and closePos or openPos
	image:TweenPosition(chosenPos, Enum.EasingDirection.InOut, Enum.EasingDirection.Linear, 0.5, true)
	open = not open
end)

So it makes the closePos the original position of the radio and the openPos the position of the radio but with a decrease so it goes up as an example

Again, localscript inside of that radio ImageLabel, you will need to convert the ImageLabel to an ImageButton for this to work, there should be a plugin to easily convert that for you, such as

its in a script where should i place it

It depends on where your script is located and where your ScreenGui object is located. This tutorial here (Learn Roblox) is a good place to learn the basics of referencing objects in your game while also manipulating them, through code.

That’s not working still, it’s an ImageButton and the script is a LocalScript inside the ImageButton, what have I done wrong?

What’s happening when you press it?

1 Like

Absolutely nothing

onlythirtycharacters

@EmbatTheHybrid pls help, its not working

Did you remember to put it in the Button itself? Are you getting any errors?

It’s in the button, I get a black cursor saying it is clickable but nothing happens when I click it

Is the output displaying any error?

10:14:47.222 Linear is not a valid member of “Enum.EasingDirection” - Client - LocalScript:12

My bad! Change it to this

local image = script.Parent

local open = false

local pos = image.Position

local closePos = pos
local openPos = UDim2.new(pos.X.Scale,pos.X.Offset,pos.Y.Scale - 0.1, pos.Y.Offset)

image.MouseButton1Click:Connect(function()
	local chosenPos = open and closePos or openPos
	image:TweenPosition(chosenPos, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.5, true)
	open = not open
end)
1 Like

If I were to make it, when you click it, aswell as going on screen, this audio plays (rbxassetid://6066104082). How would I do that?

Put a Sound instance in the ImageButton with that id and just add some code around

local image = script.Parent

local open = false

local pos = image.Position

local audio = image.Sound

local closePos = pos
local openPos = UDim2.new(pos.X.Scale,pos.X.Offset,pos.Y.Scale - 0.1, pos.Y.Offset)

image.MouseButton1Click:Connect(function()
	local chosenPos = open and closePos or openPos
	image:TweenPosition(chosenPos, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.5, true)
	audio:Play()
	open = not open
end)

Sound is the name of the sound instance in the ImageButton, you’d have ot rename it if you change the name of it

1 Like

How do I make it that it only plays when opening it