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

Why will this not work? It says error on line 1! Is there a problem with the 'and' system?

Ok... So the problem. 21:03:24.438 - Players.Player1.PlayerGui.ScreenGui.Menu.Choices.Script:11: 'end' expected (to close 'function' at line 1) near ''

This is the script:

function onButtonClicked()
if script.Parent.Drink.Value == No and
	script.Parent.Main.Value == No and
	script.Parent.Pudding.Value == No and
	script.Parent.Snack.Value == No and
	script.Parent.Starter.Value == No then
	script.Parent.Parent.Not_selected.Visible = true else
	script.Parent.Value.Value = true
end

script.Parent.Parent.Submit.MouseButton1Click:Connect(onButtonClicked)> 

So... I don't really know what to say. Can you help me? (If I have to, I'll send screenshots on skype/discord.

2 comments

1

You only have 1 end. You have to end both the function and the if statement. Add another end after line 9.

0

you have to close the if statement

2 answers

✓ Accepted answer
function onButtonClicked()
if script.Parent.Drink.Value == No and
    script.Parent.Main.Value == No and
    script.Parent.Pudding.Value == No and
    script.Parent.Snack.Value == No and
    script.Parent.Starter.Value == No then
    script.Parent.Parent.Not_selected.Visible = true else
    script.Parent.Value.Value = true
end

script.Parent.Parent.Submit.MouseButton1Click:Connect(onButtonClicked)

On line #07 on the post you forgot to put a 'then' after the 'true' and before the 'else'. Simple mistake really. Not sure what the symbol after line #11 was for, but that shouldn't be there. Also, to make the script just a tiny bit more clean, try this script:

script.Parent.Parent.Submit.MouseButton1Click:connect(function()
if script.Parent.Drink.Value == No and
    script.Parent.Main.Value == No and
    script.Parent.Pudding.Value == No and
    script.Parent.Snack.Value == No and
    script.Parent.Starter.Value == No then
    script.Parent.Parent.Not_selected.Visible = true else
    script.Parent.Value.Value = true
end)

This simply does the same thing with shaving off a line. In my opinion, every extra line counts. Hope this works and if not let me know please!

3 comments

0

"then else" is not a thing.

0

Oh my wait a second

0

I'll change that... Hope this works.

I appreciate all your answers, but I realised the closest to fixing the problem was the answer I chose. This is the new script:

function onButtonClicked()
if script.Parent.Drink.Value == ("No") and
	script.Parent.Main.Value == ("No") and
	script.Parent.Pudding.Value == ("No") and
	script.Parent.Snack.Value == ("No") and
	script.Parent.Starter.Value == ("No") then
	script.Parent.Parent.Not_selected.Visible = true else
	script.Parent.Value.Value = true
end
end
script.Parent.Parent.Submit.MouseButton1Click:Connect(onButtonClicked)

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