How to make a Check Box

Hi, devs! To make a check box, so I am following the steps:

  1. Create a Screen GUI and make a check box. So, these are no effect on each other.
    Capture d’écran 2022-09-03 132141

  2. Rename the Object name in the Explorer Button called “CheckBoxButton”.

  3. Make a script that check box can work:

local Button = script.Parent
local Check = Button.Check

Button.MouseButton1Click:Connect(function()
 Check.Visible = not Check.Visible
  1. Watch this video that can result:

  2. Enjoy your working check box!

You can also put the action in your GUI by following steps:

  1. Insert any object if you want. For example, the text label is called “Checked”.
    Capture d’écran 2022-09-03 140906

  2. Add an Instance on your script below:

	if Check.Visible == false then
		Checked.TextColor3 = Color3.new(0.333333, 1, 0)
		Checked.Text = "Checked"
		Check.Visible = true
	elseif Check.Visible == true then
		Checked.TextColor3 = Color3.new(1, 0, 0)
		Checked.Text = "Not Checked"
		Check.Visible = false
	end
  1. Watch also in this result of a check box with any actions of objects:

  2. Enjoy also with your object actions!

Thanks for greeting with your check box! :grin:

Sound so good. :smile:

9 Likes

Can you explain your scripts

Pls

4 Likes

When making a tutorial, you’re supposed to explain to the viewers, what they see and how does your resource work.

4 Likes

Before I explain this, please add this to the line 5:

ocal Button = script.Parent
local Check = Button.Check

Button.MouseButton1Click:Connect(function()
	if Check.Visible == false then
		Checked.TextColor3 = Color3.new(0.333333, 1, 0)
		Checked.Text = "Checked"
		Check.Visible = true
	elseif Check.Visible == true then
		Checked.TextColor3 = Color3.new(1, 0, 0)
		Checked.Text = "Not Checked"
		Check.Visible = false
	end
end

I will explain this. What you should ask me?

I mean explain in the code itself

example, (oof these skills)

local something = workspace.part -- Variable, naming the part
something.BrickColor = really red -- Making that part really red
end -- end of the code

like that

Would recommend using .Activated event instead of .MouseButton1Click for the button, which has mobile support. Also explain in detail your code like others said. Still, cool resource for starter scripters.

Like a code, I explain to do this:

local Button = script.Parent
local Check = Button.Check
local something = workspace -- Variable, naming the part

Button.MouseButton1Click:Connect(function()
	if Check.Visible == false then
		something.Brickcolor = Brickcolor.new("Lime Green") -- Making that part really red
		Check.Visible = true
	elseif Check.Visible == true then
		something.Brickcolor = Brickcolor.new("Really Red")
		Check.Visible = false
	end
end -- end of the code

For example, do it yourself, or try it.

1 Like

Yes, I will try to use this code like in mobile support:

local Button = script.Parent
local Check = Button.Check

Button.Activated:Connect(function()
	if Check.Visible == false then
		Checked.TextColor3 = Color3.new(0.333333, 1, 0)
		Checked.Text = "Checked"
		Check.Visible = true
	elseif Check.Visible == true then
		Checked.TextColor3 = Color3.new(1, 0, 0)
		Checked.Text = "Not Checked"
		Check.Visible = false
	end
end

This code will work in mobile device support. :wink:

Ternary is cool

local Button = script.Parent
local Check = Button.Check
local falseColor = Color3.new(0.333333, 1, 0)
local trueColor = Color3.new(1, 0, 0)

Button.Activated:Connect(function()
	Check.Visible = not Check.Visible
    Checked.Text = Checked.Text == "Checked" and "Not checked" or "Checked"
    Checked.TextColor3 = Checked.TextColor3 == falseColor and trueColor or falseColor
end

We removed 6 lines with ternary so we removed 80% (the previous code had 20 lines, mine has only 16, 16 / 20 * 100 = 80) of the previous code’s lines. You can use the luau’s official ternary instead of the fake one I used, but wanted to point out that save.

2 Likes