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

Expected 'end' to close 'do', got 'else'?

I've been trying to make certain bricks change colour when a specific player joins, but else on line 23 is always causing an error because it's expecting an end to close do, but got else and I don't know the solution to it. Not even my goto solution of spamming ends worked.

local playerx = {"cpexo, cpoxo"}

local function Transparency()
	for i,v in pairs(workspace:GetChildren()) do
	if v.Name == "Part1" then do
			v.Transparency = 0.5	
		end
		end
	end
end

local function ColorChange()
	for i,v in pairs(workspace:GetChildren()) do
		if v.Name == "Part1" then do
				v.BrickColor = BrickColor.new("Really Red")
			end
		end
	end
end
	
game.Players.PlayerAdded:Conenct(function(Player)
if table.find(playerx, Player.Name) then do
			Transparency() else do
			ColorChange()
		end
	end	
end

1 comment

0

are you sure you need so many 'do's? have you tried it without them? also every do needs its own end

2 answers

In your if statements, you are saying if ... then do. You don't want to put the do there, that is what is breaking your scripts. Also, you don't want else do, you want else. Else goes on a seperate line. Your code is:

if ... then do
     Code else do
     Code2
end

When it should be:

if ... then
     Code
else
     Code2
end

I hope this makes sense and answers your question.

4 comments

0

Also, I think you put an extra end in all of your functions

0

Yeah, you did

0

Thanks, this was the answer and in conjunction to this, I've misspelled connect wrong too. How do I mark this as answered?

0

There is a button underneath comments that says "Accept Answer" (or something similar to that)

you dont need all those dos in your if statements. try:

local playerx = {"cpexo, cpoxo"}

local function Transparency()
    for i,v in pairs(workspace:GetChildren()) do
		if v.Name == "Part1" then 
			v.Transparency = 0.5    
		end
    end
end

local function ColorChange()
    for i,v in pairs(workspace:GetChildren()) do
        if v.Name == "Part1" then 
			v.BrickColor = BrickColor.new("Really Red")
        end
    end
end

game.Players.PlayerAdded:Conenct(
	function(Player)
		if table.find(playerx, Player.Name) then 
			Transparency() 
		else 
			ColorChange()
		end 
	end
end)

the if then do statements are valid but it makes things a lot more complex as you've descovered. Things tend to break easy.

Hope this helps!

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