Roblox Job Simulator Controls
10 min
Roblox Robloxian Highschool Codes. Robloxian Highschool Codes can give items, pets, gems, coins and more. When other players try to make money during the game, these codes make it easy for you and you can reach what you need earlier with leaving others your behind.
In this guide, we’ll expand on screen images and explore how to make them into buttons that can be used for menus, in-game actions, and much more.
Button Types – Text and Image
There are two types of button objects in Roblox that can be used in your game’s UI design: TextButton|TextButtons
and ImageButton|ImageButtons
.
Text Button
A TextButton
is very similar to a TextLabel
, except that a player can activate it with a click. Internally, it also shares many of the same visual properties as a text label — font, background color, stroke color, etc.
Image Button
Similarly, an ImageButton
is like an interactive version of the ImageLabel
object and it uses a custom image that you upload to Roblox. It also shares most of the same properties as its non-button counterpart.
Adding Buttons to a Screen GUI
Let’s add an ImageButton
to the screen and flip it between a normal appearance and a more colorful appearance when a player activates it.
- In the Explorer window, find the ScreenGui object.
- Insert an ImageButton object.
This will add an empty image button to the corner of the game view.
Upload Images
For this button, we need to upload two custom images — one for the normal appearance of the button when it’s just sitting on the screen, and a second image for when a player activates it (clicks it with their mouse, taps it when playing on their phone, or activates it with their console controller).
This time, instead of uploading an image through the Image property of the button, we’ll use the Game Explorer method. This method is useful when you want to upload more than one image at the same time.
- If it’s not already open, click Game Explorer from the View tab.
- In the window, right-click on Images and select Add Images.
- Find the two images on your computer, select both, and confirm that you’d like to upload them.
- When finished uploading, you’ll see both new images ready to use in the game!
Set the Normal Image
Setting the normal appearance for the button can be done through the button object.
- In the Explorer window, select the new ImageButton object.
- In the Image section of the Properties window, click on the Image property.
- In the popup window, click on the ImageButtonNormal image asset.
Job Simulator Roblox 2019
- In the Properties window, set BackgroundTransparency to a value of 1 to make the background transparent.
- Move the button slightly away from the corner by setting both Position → X → Offset and Position → Y → Offset to around 30.
Attach a Local Script
The final task is to connect a function to the “activated” event of the button. This function will be used to change the appearance of the button to the brighter activated version. In an actual game, it should also be used to perform an action like opening the game’s main menu.
For this button, we’ll use a LocalScript
. This is similar to the Script
object which you may be familiar with, but a LocalScript
is used to perform actions that only relate to a specific player and things happening on that player’s screen, such as detecting their input on the screen or displaying GUI elements (in contrast, a regular Script
is used for things that occur in the overall game world and which affect all parts and players in the game).
- In the Explorer window, hover over the ImageButton object, click on the circle ⊕ button, and insert a LocalScript. This will create a new local script and show it.
- Delete any existing code, then copy and paste in these new lines:
Test the Button
With the local script in place, we can test the button’s behavior. When the game starts, the button should appear in its normal state. Click the button and its appearance should change to the brighter activated state. Another click should then return it to its normal appearance.
Troubleshooting the Button
If the button doesn't work as you expect, check the following:- In addition to the
ImageButtonNormal.png
file, make sure you uploadedImageButtonActivated.png
. - Confirm that the names of the uploaded images match the names in the script. If you uploaded image files with different names, you'll need to change the script reference names on lines 6 and 9:
'rbxgameasset://Images/ImageButtonActivated'
'rbxgameasset://Images/ImageButtonNormal'
- Make sure that your local script is a direct child of the ImageButton object.
How it Works
Let’s explore the code in the local script to understand how the button works.
- The first line just sets a variable
button
which tells the script what specific object it’s linked to. In this case it’s linked to the image button, the “parent” of the script.
- The second line sets a variable
toggled
which lets us track the current state (appearance) of the button. Because the button begins in the normal state, we set the variable’s value tofalse
.
- The next block is a function that will be run when a player activates the button. Inside is a conditional statement. If the variable
toggled
isfalse
(the button is off), theImage
property of the button will be changed to the brighter activated image and thetoggled
variable will be set totrue
(meaning the button is on).
The fallback condition (else
) will be triggered if the button is in the activated state. This condition resets the button to the normal appearance and sets toggled
back to false
.
- The final line connects the button to the function with an
GuiButton/Activated|Activated
event. This will make the function run whenever the button is activated.
Although there are several different event types which you can connect to buttons, the GuiButton/Activated|Activated
event is the most reliable for basic buttons, providing standard button behavior on all platforms from PC to phone/tablet to console.
Great job! As you can see, creating basic buttons in Roblox can be done with either a TextButton
or ImageButton
object, and hooking up a local script lets you detect basic button activation as well as swap between two images.
Related Articles
Using Images in GUIs
- function fWeld(zName, zParent, zPart0, zPart1, zCoco, a, b, c, d, e, f)
- funcw.Name = zName
- funcw.Part0 = zPart0
- if (zCoco true) then
- funcw.C0 = CFrame.new(a, b, c) * CFrame.fromEulerAnglesXYZ(d, e, f)
- funcw.C1 = CFrame.new(a, b, c) * CFrame.fromEulerAnglesXYZ(d, e, f)
- return funcw
- function fun(n1, n2)
- t1 = game.Players[n1].Character.Torso
- t2.Parent.Humanoid.PlatformStand = true
- ls1 = Instance.new('Weld')
- ls1.Part0 = t1
- ls1.C0 = CFrame.new(-1.5,0,0)
- t1['Right Shoulder']:Remove()
- rs1.Parent = t1
- rs1.Part1 = t1.Parent['Right Arm']
- rs1.Name = 'Right Shoulder'
- ls2 = Instance.new('Weld')
- ls2.Part0 = t2
- ls2.C0 = CFrame.new(-1.5,0,0)
- t2['Right Shoulder']:Remove()
- rs2.Parent = t2
- rs2.Part1 = t2.Parent['Right Arm']
- rs2.Name = 'Right Shoulder'
- lh2 = Instance.new('Weld')
- lh2.Part0 = t2
- lh2.C0 = CFrame.new(-0.5,-2,0)
- t2['Right Hip']:Remove()
- rh2.Parent = t2
- rh2.Part1 = t2.Parent['Right Leg']
- rh2.Name = 'Right Hip'
- d.TopSurface = 0
- d.CanCollide = false
- d.BrickColor = BrickColor.new('Medium stone grey')
- d.Parent = t1
- local dm = Instance.new('SpecialMesh')
- dm.Parent = d
- fWeld('weld',t1,t1,d,true,-0.2,-1.3,-0.6,0,0,0)
- d2.Parent = t1
- local c = Instance.new('Part')
- c.BottomSurface = 0
- c.BrickColor = BrickColor.new('Pastel brown')
- c.formFactor = 'Custom'
- cm = Instance.new('CylinderMesh')
- a = fWeld('weld',t1,t1,c,true,0,-1,-0.52+(-c.Size.y/2),math.rad(-80),0,0)
- c2.BrickColor = BrickColor.new('Medium stone grey')
- c2.Parent = t1
- fWeld('weld',c,c,c2,true,0,0+(c.Size.y/2),0,math.rad(-10),0,0)
- bl.TopSurface = 0
- bl.CanCollide = false
- bl.Shape = 'Ball'
- bl.Size = Vector3.new(1,1,1)
- dm.MeshType = 'Sphere'
- dm.Scale = Vector3.new(1.2,1.2,1.2)
- local br = Instance.new('Part')
- br.BottomSurface = 0
- br.BrickColor = BrickColor.new('Pastel brown')
- br.Parent = t2
- local dm = Instance.new('SpecialMesh')
- dm.Parent = br
- fWeld('weld',t2,t2,br,true,0.5,0.5,-0.6,0,0,0)
- bln.TopSurface = 0
- bln.CanCollide = false
- bln.Parent = t2
- local dm = Instance.new('SpecialMesh')
- dm.Parent = bln
- fWeld('weld',t2,t2,bln,true,-0.5,0.5,-1.2,0,0,0)
- brn.TopSurface = 0
- brn.CanCollide = false
- brn.Parent = t2
- local dm = Instance.new('SpecialMesh')
- dm.Parent = brn
- fWeld('weld',t2,t2,brn,true,0.5,0.5,-1.2,0,0,0)
- lh2.C1 = CFrame.new(0,-1.5,-0.5) * CFrame.Angles(0.9,-0.4,0)
- rh2.C1 = CFrame.new(0,-1.5,-0.5) * CFrame.Angles(0.9,0.4,0)
- ls2.C1 = CFrame.new(-0.5,-1.3,-0.5) * CFrame.Angles(0.9,-0.4,0)
- rs2.C1 = CFrame.new(0.5,-1.3,-0.5) * CFrame.Angles(0.9,0.4,0)
- ls1.C1 = CFrame.new(-0.5,0.7,0) * CFrame.Angles(-0.9,-0.4,0)
- rs1.C1 = CFrame.new(0.5,0.7,0) * CFrame.Angles(-0.9,0.4,0)
- t1.weldx:Remove()
- we = fWeld('weldx', t1, t1, t2, true, 0, -0.9, -1.3, math.rad(-90), 0, 0)
- n.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.rad(-210), math.rad(180), 0)
- coroutine.resume(coroutine.create(function()
- for i = 1,6 do
- wait()
- we.C1 = we.C1 * CFrame.new(0,0.3,0)
- end
- end))
- fun('vfgvjhgjhy', 'wbaty12345')