"else" keeps erroring in script

  1. What do you want to achieve? I’m trying to make a button where every time you click it it changes the text.

  2. What is the issue? The script works just fine if its only one “else” but when I add another it breaks.
    image

  3. What solutions have you tried so far? I looked everywhere.

s.MouseButton1Click:Connect(function()
	if db == true then
		s.Text = tostring("-")
		db = false
	else
		s.Text = tostring("/")
		db = false
		else -- this errors
	s.Text = tostring("/")
	db = false
	end
end)

you cant have more than one else in an if statement. you can have as many elseif statements though.

Perhaps your code should just be:

s.MouseButton1Click:Connect(function()
	if db == true then
		s.Text = tostring("-")
		db = false
	else
		s.Text = tostring("/")
		db = true
	end
end)

or better said as

s.MouseButton1Click:Connect(function()
    s.Text = (db and "-") or "/"
    db = not db
end)

Bruh that literally doesnt solve the problem… I want 2 more s.text changes

You are using a boolean. They have two states. If you want to cycle through a list of characters when clicking then perhaps put them in an array and have a counter variable.

local states = {
    "-",
    "/",
    "some other symbol"
}

local db = 1

s.MouseButton1Click:Connect(function()
    s.Text = states[db]
    db = db % #states + 1
end)
1 Like

Ohhh thank you, I should of thought of that I’ll see if it works