Else not working

hello, i don’t understand why this else statement is not working. When the level is 0 and selected is “”, and dungeonName = “” it works but when it’s not it doesn’t work why?

print(Selected)
	print(level)
	if Selected == "" then
		print("not Selected")
		if level <= 0 then
			print("levle")
			if DungeonName == "" then
				print("Error")
				script.Parent.Parent.Errormsg.Visible = true
				wait(1)
				script.Parent.Parent.Errormsg.Visible = false
			else
				game.ReplicatedStorage.Events.CreateParty:FireServer(hardcore, Selected, level, DungeonName, GamesMade)
				print("Fired")
				script.Parent.Parent.Parent.CreateFrame.Visible = false
1 Like

Try to put a print/warn line before the “game.Re” (…) to see if the else works, can be the Remote Event that doesn’t work.

did you forget the end? or did you just not send the full script?

im just not sending the full script, if you want i can

When testing for the else, is selected still equal to “” and level still 0?

That doesn’t work either, same problem the only thing different is it’s just warning

yes, but when i change it, the remote doesn’t fire

What do you want the code to do? Are you checking that each variable (selected, level and dungeon name) are valid before creating the party?

yes, im making sure if the selected is an actual string and not empty, if the level is higher than 0, and if the dungeon is an actual dungeon and not blank. Before creating the party

print(Selected)
print(level)

local valid = true
if Selected == "" then
	print("not Selected")
	valid = false
elseif level <= 0 then
	print("levle")
	valid = false
elseif DungeonName == "" then
	print("Error")
	script.Parent.Parent.Errormsg.Visible = true
	wait(1)
	script.Parent.Parent.Errormsg.Visible = false
	valid = false
end

if valid == true then
	game.ReplicatedStorage.Events.CreateParty:FireServer(hardcore, Selected, level, DungeonName, GamesMade)
	print("Fired")
	script.Parent.Parent.Parent.CreateFrame.Visible = falseprint("Hello world!")
end

Try this. I have not tested it so if there’s a warning reply with the error.

1 Like

it doesn’t check Dungeonname it only checks if one of them is true

I’m confused, I thought you wanted to check all 3 of them were valid before creating the party?

The difference between your code and my code is that in your code if selected was not empty, then it would not check the rest of the variables. However, with mine, it would go through each variable until it reaches an invalid one or the end of the statements.

Please correct me if I am wrong, I may be misunderstanding!

1 Like

doesn’t elseif check if one of those is right, if one of these is true then it’s going to work im pretty sure since i didn’t add a name to the party but it still let me create it

if Selected == "" then
		print("not Selected")
		valid = false
	elseif level <= 0 then
		print("levle")
		valid = false
	elseif DungeonName == "" then

It shouldn’t do.

On line 1 (of the shortened code you just put), it will check if selected is empty. If so, then valid = false and the party will not be created. If slected is not empty, the statement is false and therefore it moves onto line 4, the first elseif. If level is less than or equal to 0, the statement is true and valid = false, and the party will not be created. If level is higher than 0, then it moves onto the last else if, if dungeon name is empty. If it is empty, then valid = false. Otherwise, the end of the if statement is reached, and valid is still equal to true, and the party is created.

Is this what you wanted? Hopefully I’m not just being really stupid and misunderstanding simple code.

Oh nvm i was being stupid sorry, it works :smiley:

Oh that’s good, you had me worried there that it was me :joy: I’m glad I could help!

1 Like