Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

whats wrong with my script??? end expected near else

so, i was scripting and i noticed that it wanted me to put an end near "else", i tried doing that in many different ways and nothing worked. can someone help me out and correct my code?

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.ColorGradientFrame.Visible = true
	script.Parent.ColorGradientFrame2.Visible = true
	script.Parent.DarknessGradientFrame.Visible = true
	script.Parent.DarknessGradientFrame2.Visible = true
	else
	script.Parent.ColorGradientFrame.Visible = false
	script.Parent.ColorGradientFrame2.Visible = false
	script.Parent.DarknessGradientFrame.Visible = false
	script.Parent.DarknessGradientFrame2.Visible = false
end)

1 comment

0

You include else on line 6 but there is no if statement, that is the problem. Try replacing every true on lines 2-5 with "not script.Parent.blah.Visible". If Visible = true, it will turn false since not true = false. If Visible = false, it will turn true since not false = true

1 answer

Your problem is that you used else with no if statement. Else should be used in situations where there are two possible outcomes that rely on a statement being true or false. I'm going to assume that you just want to make the color gradient visible and invisible per click. That would look like this:

script.Parent.MouseButton1Click:Connect(function()
	if not script.Parent.ColorGradient.Frame.Visible then
	    script.Parent.ColorGradientFrame.Visible = true
	    script.Parent.ColorGradientFrame2.Visible = true
	    script.Parent.DarknessGradientFrame.Visible = true
	    script.Parent.DarknessGradientFrame2.Visible = true
	else -- else means that any situation that the Frame isn't visible, the following lines will run
	    script.Parent.ColorGradientFrame.Visible = false
	    script.Parent.ColorGradientFrame2.Visible = false
	    script.Parent.DarknessGradientFrame.Visible = false
	    script.Parent.DarknessGradientFrame2.Visible = false
	end
end)

Comment if you have any questions as to how that works. Hope I helped!

1 comment

1

Great answer! I finally figured it out where to place the "not" on if statements lol funny......

This discussion is preserved as it was. New answers, comments, and votes are closed.