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
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.
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!