Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
cpexo 5
4 years ago

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

0
are you sure you need so many 'do's? have you tried it without them? also every do needs its own end misha123 83 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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.

0
Also, I think you put an extra end in all of your functions IAmNotTheReal_MePipe 418 — 4y
0
Yeah, you did IAmNotTheReal_MePipe 418 — 4y
0
Thanks, this was the answer and in conjunction to this, I've misspelled connect wrong too. How do I mark this as answered? cpexo 5 — 4y
0
There is a button underneath comments that says "Accept Answer" (or something similar to that) IAmNotTheReal_MePipe 418 — 4y
Ad
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

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!

Answer this question