Error (69,5) Expected 'end' (to close 'function' at line 1), got <eof>

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make the script work?
  2. What is the issue? Include screenshots / videos if possible!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried rearranging the script around a bit, but nothing has worked yet soo…

Script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		local Nametag = script.NameTag:Clone()
		Nametag.Parent = plr.Character.Head
		plr.Character.Humanoid.NameDisplayDistance = 0 -- line 5
		Nametag.name.Text = plr.Name
		Nametag.name.TextColor3 = plr.Team.TeamColor.Color
		Nametag.Rank.TextColor3 = plr.Team.TeamColor.Color
		if plr:IsInGroup(5925127) and plr.Team ~= game.Teams.Patient then
			Nametag.Rank.Text = plr:GetRoleInGroup(5925127)
		else
			Nametag.Rank.Text = plr.Team.Name
		end
		if plr:IsInGroup(000) then
			Nametag.Dev.Visible = true
			Nametag.Dev.Text = plr:GetRoleInGroup(000)
			if plr.Name == "49dec" then
				Nametag.Dev.Text = "Development Director"
			end
		else
			Nametag.Dev.Visible = false
		end
		if plr.Team == game.Teams["Death Unit"] then
			print(1)
			Nametag.name.Text = ""
			Nametag.Rank.Text = "Death Unit"
			Nametag.name.TextColor3 = BrickColor.Black()
		 end
		if plr:IsInGroup(5927318) and plr.Team == game.Teams["Emergency Response Team"] then
			Nametag.Rank.Text = "[SOU] ".. plr:GetRoleInGroup(5927318)
		end
		if plr.Team == game.Teams["Site Security"] then
			if plr:IsInGroup(000) then
				Nametag.Rank.Text = plr:GetRoleInGroup(000)
			else
				Nametag.Rank.Text = "Cadet"
			end
		end
		if plr.Team == game.Teams["Foxtrot Moderation Team"] then
			Nametag.Rank.TextColor3 = Color3.fromRGB(41, 98, 255)
			Nametag.Rank.Text = "Official Foxtrot Moderator"
			Nametag.name.TextColor3 = Color3.fromRGB(170, 0, 255)
			Nametag.name.Text = plr.Name
		end
		if plr.Team == game.Teams["Specialized Protection Unit"] then
			if plr:IsInGroup(5927358) then
				Nametag.Rank.Text = "[REDACTED]"
				Nametag.name.Text = ""
		end
		if plr.Team == game.Teams["Hospital Intelligence"] then
			if plr:IsInGroup(5927255) then
				Nametag.Rank.Text = "[EXPUNGED]"
				Nametag.name.Text = ""
				Nametag.name.TextColor3 = BrickColor.Black()
			end
		if plr.Team == game.Teams["Specialised Operations Unit"] then
			if plr:IsInGroup(5927318) then
				Nametag.Rank.Text = plr:GetRoleInGroup(5927318)
			else
				Nametag.Rank.Text = "SOU Cadet"
			end	
		if plr.Team == game.Teams["Patient Leader"] then
				Nametag.Rank.Text = "Patient Leader"
				Nametag.name.TextColor3 = BrickColor.Gold()
		 end
	end
end
end
end) -- line 69
1 Like

You’re missing an ) to close of the :Connect call for CharacterAdded. The second-to-last end, append a ) to it.

What? I’m a bit confused at the moment.

You didn’t close this.
image

I added end) instead of end to the second to last send, and now it gave a new error:

if plr.Team == game.Teams["Specialized Protection Unit"] then
		if plr:IsInGroup(5927358) then
			Nametag.Rank.Text = "[REDACTED]"
			Nametag.name.Text = ""
	end

This line is also not closed properly. You have two ifs but only one end.

		if plr:IsInGroup(000) then
			Nametag.Dev.Visible = true
			Nametag.Dev.Text = plr:GetRoleInGroup(000)
			if plr.Name == "49dec" then
				Nametag.Dev.Text = "Development Director"
			end
		else
			Nametag.Dev.Visible = false
		end
		if plr.Team == game.Teams["Death Unit"] then
			print(1)
			Nametag.name.Text = ""
			Nametag.Rank.Text = "Death Unit"
			Nametag.name.TextColor3 = BrickColor.Black()
		 end
		if plr:IsInGroup(5927318) and plr.Team == game.Teams["Emergency Response Team"] then
			Nametag.Rank.Text = "[SOU] ".. plr:GetRoleInGroup(5927318)
		end
		if plr.Team == game.Teams["Site Security"] then
			if plr:IsInGroup(000) then
				Nametag.Rank.Text = plr:GetRoleInGroup(000)
			else
				Nametag.Rank.Text = "Cadet"
			end
		end
		if plr.Team == game.Teams["Foxtrot Moderation Team"] then
			Nametag.Rank.TextColor3 = Color3.fromRGB(41, 98, 255)
			Nametag.Rank.Text = "Official Foxtrot Moderator"
			Nametag.name.TextColor3 = Color3.fromRGB(170, 0, 255)
			Nametag.name.Text = plr.Name
		end
		if plr.Team == game.Teams["Specialized Protection Unit"] then
			if plr:IsInGroup(5927358) then
				Nametag.Rank.Text = "[REDACTED]"
				Nametag.name.Text = ""
		end
		if plr.Team == game.Teams["Hospital Intelligence"] then
			if plr:IsInGroup(5927255) then
				Nametag.Rank.Text = "[EXPUNGED]"
				Nametag.name.Text = ""
				Nametag.name.TextColor3 = BrickColor.Black()
			end
		if plr.Team == game.Teams["Specialised Operations Unit"] then
			if plr:IsInGroup(5927318) then
				Nametag.Rank.Text = plr:GetRoleInGroup(5927318)
			else
				Nametag.Rank.Text = "SOU Cadet"
			end	
		if plr.Team == game.Teams["Patient Leader"] then
				Nametag.Rank.Text = "Patient Leader"
				Nametag.name.TextColor3 = BrickColor.Gold()
		 end
	end
end
end)
end)

Then all this is wrong?

		if plr.Team == game.Teams["Specialised Operations Unit"] then
			if plr:IsInGroup(5927318) then
				Nametag.Rank.Text = plr:GetRoleInGroup(5927318)
				end -- I added an end to here, and it got rid of the error soo..
			else
				Nametag.Rank.Text = "SOU Cadet"
			end	

You shouldn’t simply “put an end… oh the errors gone… so why isn’t it working?”
Double check all your ifs statements and where they close.

I fixed your entire code, your whole issue’s just your if statements not closing where they’re supposed to.

game.Players.PlayerAdded:Connect(function(plr)
        plr.CharacterAdded:connect(function(char)
                local Nametag = script.NameTag:Clone()
                Nametag.Parent = plr.Character.Head
                plr.Character.Humanoid.NameDisplayDistance = 0 -- line 5
                Nametag.name.Text = plr.Name
                Nametag.name.TextColor3 = plr.Team.TeamColor.Color
                Nametag.Rank.TextColor3 = plr.Team.TeamColor.Color
                if plr:IsInGroup(5925127) and plr.Team ~= game.Teams.Patient then
                    Nametag.Rank.Text = plr:GetRoleInGroup(5925127)
                else
                    Nametag.Rank.Text = plr.Team.Name
                end
                if plr:IsInGroup(000) then
                    Nametag.Dev.Visible = true
                    Nametag.Dev.Text = plr:GetRoleInGroup(000)
                    if plr.Name == "49dec" then
                        Nametag.Dev.Text = "Development Director"
                    end
                else
                    Nametag.Dev.Visible = false
                end
                if plr.Team == game.Teams["Death Unit"] then
                    print(1)
                    Nametag.name.Text = ""
                    Nametag.Rank.Text = "Death Unit"
                    Nametag.name.TextColor3 = BrickColor.Black()
                end
                if plr:IsInGroup(5927318) and plr.Team == game.Teams["Emergency Response Team"] then
                    Nametag.Rank.Text = "[SOU] " .. plr:GetRoleInGroup(5927318)
                end
                if plr.Team == game.Teams["Site Security"] then
                    if plr:IsInGroup(000) then
                        Nametag.Rank.Text = plr:GetRoleInGroup(000)
                    else
                        Nametag.Rank.Text = "Cadet"
                    end
                end
                if plr.Team == game.Teams["Foxtrot Moderation Team"] then
                    Nametag.Rank.TextColor3 = Color3.fromRGB(41, 98, 255)
                    Nametag.Rank.Text = "Official Foxtrot Moderator"
                    Nametag.name.TextColor3 = Color3.fromRGB(170, 0, 255)
                    Nametag.name.Text = plr.Name
                end
                if plr.Team == game.Teams["Specialized Protection Unit"] then
                    if plr:IsInGroup(5927358) then
                        Nametag.Rank.Text = "[REDACTED]"
                        Nametag.name.Text = ""
                    end
                end
                if plr.Team == game.Teams["Hospital Intelligence"] then
                    if plr:IsInGroup(5927255) then
                        Nametag.Rank.Text = "[EXPUNGED]"
                        Nametag.name.Text = ""
                        Nametag.name.TextColor3 = BrickColor.Black()
                    end
                end
                if plr.Team == game.Teams["Specialised Operations Unit"] then
                    if plr:IsInGroup(5927318) then
                        Nametag.Rank.Text = plr:GetRoleInGroup(5927318)
                    else
                        Nametag.Rank.Text = "SOU Cadet"
                    end
                end
                if plr.Team == game.Teams["Patient Leader"] then
                    Nametag.Rank.Text = "Patient Leader"
                    Nametag.name.TextColor3 = BrickColor.Gold()
                end
            end)
    end) -- line 69

The script editor also has this useful thing, use it to check. image

How do you usually write your code? Does your Script Editor autocomplete scopes when opened? Usually you should be able to catch these issues immediately when you come across a red underline. There’s also an option in the context menu to view the offending line.

You can catch these pretty quickly if you use proper indenting and close your scopes first before writing the body for that scope. For example, if I’m writing out a function, the Script Editor will usually close that scope for me. If it doesn’t, I write out the end and align it first before anything else.

I don’t believe my script editor does that.

Make sure to indent properly when writing code. Scripts that end like this:

end
end
end)
end

make it more difficult to find syntax problems.