Elseif not working at all

I need help with the elseif statement not checking (at all)

button.MouseButton1Click:Connect(function()
	button.Visible = false
	textBox.Visible = false
	Txtbox2.Visible = false
	local mol = math.random(0, 100)
	local refm = math.random(0,100)
	
	if mol >= percentage_sp or refm >= percentage_ref then
		if Txtbox2.Text ~= "" then
			MaximumCount = tonumber(Txtbox2.Text)
		else
			MaximumCount = 4
		end
		match(noob1, 0.5)
		match(noob2, 1)
		match(noob3, 2.5)
		match(noob4, 1)
		match(noob5, 0.5)
		button.Visible = true
		textBox.Visible = true
		Count.Value = 0
		Txtbox2.Visible = true
		percentage_sp += 5
		print(percentage_sp)
		percentage_ref += 10
		print(percentage_ref)
		print(refm)
	elseif mol <= percentage_sp then
		print(5)
		button.Visible = false
		textBox.Visible = false
		Txtbox2.Visible = false
		
		spawn(function()MakeBubble("푸흡!!!",3) end)
		
		match(e.slash1, 0.5)
		
		spawn(function()MakeBubble("컼! 크헉!!!!", 5) end)
		
		match(e.slash2, 3)
		
		match(noob1, 0.5)
		
		button.Visible = true
		textBox.Visible = true
		Txtbox2.Visible = false
		Count.Value = 0
		percentage_sp = 10
	elseif refm <= percentage_ref then
		print(1)
		button.Visible = false
		textBox.Visible = false
		Txtbox2.Visible = false
		
		script.Parent.Parent.refill.Visible = true
		script.Parent.Parent.sfx_warning:Play()
		script.Parent.Parent.refill.MouseButton1Click:Wait()
		
		script.Parent.Parent.refill.Visible = false
		button.Visible = true
		textBox.Visible = true
		Txtbox2.Visible = true
		percentage_ref = 0
	end
end)

The first ‘elseif’ statement is working, but the second elseif statement is not working at all.
I tried printing the variable and then it said
percentage_ref = 30
refm = 28

I changed it to ‘if’ and it now works.

Just so you know, it’s because with if-statements, only at most 1 block of code will run, and that will be only if that condition was truthy (aka anything but false or nil).

if a then
    will run; exits the if-statement
elseif b then
    will run only if the previous condition was met and this condition was met; then exits the if-statement

If you have an else portion of your if-statement, that will be used as the “fallback” condition, which will run only if all of the previous conditions were not met.

if a then
    will run; exits the if statement
elseif b then
    will run only if prev. condition was falsy; then exits if statement
else
    will run only if all of the previous conditions were falsy (false or nil)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.